Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,538 members, 7,808,975 topics. Date: Thursday, 25 April 2024 at 08:20 PM

Issues With JS For Loops. Can Anyone Help Me Out? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Issues With JS For Loops. Can Anyone Help Me Out? (1013 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)

(1) (Reply) (Go Down)

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:
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?

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:


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

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:
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.
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:

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
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 1:10pm On Jan 30, 2020
Millerules:
You welcome.
So the counter wudnt go beyond the array length.

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:
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.
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:

Arrgghh. I don't really understand generators yet

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 sad
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 11:09am On Jan 31, 2020
makavele:


One day @ a time .

Solved it yet? Else, bundle the code in a zip file and send me the link.

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 smiley
Re: Issues With JS For Loops. Can Anyone Help Me Out? by Nobody: 11:09am On Jan 31, 2020
stupidity:
Just looking at the jargons you guys are spewing up there. I don’t even understand a thing.

Your employer is giving you disarray sad
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:
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?
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:

Do you expect people to download the screenshot and debug for you?
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:

While you're here naysaying and crap, some folks actually did help. So what exactly is your point in this comment?
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:

Writing out the code on a webpage will make it easier for people to read and debug.
I got the help I needed thanks very much

(1) (Reply)

Programming Errors/bugs: Six Worst Code Nightmare Of All Time / Where Can I Learn Programming Or Web Dev. In Ogun State / Coding Is Hard, How do You Get Along?

(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. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.