Stats: 3,191,787 members, 7,945,481 topics. Date: Tuesday, 10 September 2024 at 06:03 PM |
Nairaland Forum / Science/Technology / Programming / Issues With JS For Loops. Can Anyone Help Me Out? (1070 Views)
Learning React Js For Beginners / I Have This Annoying Bug In Node Js For The Past 5 Days..help / Particles.js For Web Geomtric Animations#don't Skip This (2) (3) (4)
Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 10:20am On Jan 30, 2020 |
Hey guys its strange but seems I'm having some problems getting for loops to work for me. I am trying to set the 'Next' link to get the text boxes at the bottom to loop through the array I created with the submit button and top text boxes. It seemed to work out just fine when i created just two array elements. But when I had up to five elements I discovered that my Next button skips looping through the whole array and just displays the very last element. That is what my 'Last' link is supposed to do. Who can help me out?
|
Re: Issues With JS For Loops. Can Anyone Help Me Out? by hollyfat(m): 10:40am On Jan 30, 2020 |
crownedrookie: From your code, the loop will always return the last element, you didn't specify the next element. The loop will finish and return the last element |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 11:02am On Jan 30, 2020 |
hollyfat: ![]() You are pointing out the obvious. I know I'm making a mistake and I need a solution |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Millerules(m): 12:36pm On Jan 30, 2020 |
I dnt use Javascript... But i think this should work. Create a global variable counter and set it to zero. Then in each of the next and previous function calls, increment and decrement by +1/-1 for each click. You can also get the length of the employees array and use an if statement to avoid array error. I hope this helps. |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 12:44pm On Jan 30, 2020 |
Millerules:Funny enough I just got an idea similar to this. I'll try it out later. Thanks a bunch. I don't get your meaning on using the employee.length to avoid array error though 1 Like |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Millerules(m): 12:58pm On Jan 30, 2020 |
You welcome. So the counter wudnt go beyond the array length. crownedrookie: |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 1:10pm On Jan 30, 2020 |
Millerules:Oh. Of course |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by makavele: 10:40pm On Jan 30, 2020 |
Please use a generator function which gives you the ultimate power to enter, grab items, pause, exit, re-enter, re-grab, re-pause, re-exit, etc . . . a loop or function expression at will. Your next element on your UI will just call next() and that loop will behave like a loyal slave on steroids. |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 8:19am On Jan 31, 2020 |
makavele:Arrgghh. I don't really understand generators yet |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by makavele: 9:42am On Jan 31, 2020 |
crownedrookie: One day @ a time . Solved it yet? Else, bundle the code in a zip file and send me the link. |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 10:00am On Jan 31, 2020 |
Just looking at the jargons you guys are spewing up there. I don’t even understand a thing. Your employer is giving you disarray ![]() |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 11:09am On Jan 31, 2020 |
makavele: Partly. Did some work on it last night. Both links work now. I'm just having trouble with handling the incrementation and decrementation of the counterfor Next and Prev (i++ and i--) respectively to keep it within the 0 - employees.length range. So far until my laptop ranout last night I used if (i < 0){i = 0} to reset the counter at the beginning of the Next function to reset any negative values for i but it results in displaying the first output twice. So I'm still trying to figure out the proper if logic to use. Shouldnt be an issue though. Im just starting so a bit slow. Thanks for the support man. I'm trying to be employable as a developer by march ![]() |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 11:09am On Jan 31, 2020 |
stupidity:Baba stupidity I greet you. Na legend you be. I miss that your former DP sha |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 3:17pm On Jan 31, 2020 |
crownedrookie:Do you expect people to download the screenshot and debug for you? |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 5:45pm On Jan 31, 2020 |
Cakephp:While you're here naysaying and crap, some folks actually did help. So what exactly is your point in this comment? |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 10:40pm On Jan 31, 2020 |
crownedrookie:Writing out the code on a webpage will make it easier for people to read and debug. |
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 7:36am On Feb 01, 2020 |
Cakephp:I got the help I needed thanks very much |
(1) (Reply)
. / I Need A Backend Laravel Developer For My Firm / Mtn Free Browsing Cheat For August
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 35 |