+ 3
How can I solve this code with a JS loop
Youâll understand that I mean once you open the code: There must be only one section showing up at a time. there are x amount of sections. Inside each of those sections there are buttons (â.prevâ, â.nextâ). letâs say on section1, if you click on â.nextâ, the next section shows up (section2). Etc. ââââ- the problem, for some reason I canât get the âprevâ button to work well because i also need to get the variable which tracks which section is active https://code.sololearn.com/WemEIXTm4DxW/?ref=app
6 Answers
+ 4
Ginfio đ
Another approach would be like this:
https://code.sololearn.com/W80l0huYVkI5/?ref=app
+ 3
Gordon after pulling 186 hairs out, i figured out
I will share the code with you tomorrow.
+ 3
Gordon here is how I solved it.
I removed the nextCurrent variable.
inside the if {} loop
current++
prevCurrent = current - 1;
instead of
$(...prevCurrent...).addClass("active");
$(... + current ...).removeClass("active");
now it is
$(...prevCurrent...).addClass("active");
$(... + current ...).removeClass("active");
same thing for when prevBtn is clicked.
https://code.sololearn.com/WemEIXTm4DxW
+ 2
You overcomplicated the logic.
For the callback functions, you only need to update the current, and then call a updateDisplay function, in which:
- remove active for all section
- add active for current section.
Here is a demo:
https://code.sololearn.com/WrHLer4YI7S0/?ref=app
+ 1
Gordon Iâm having a hard time understanding your code| Iâve yet got to study jquery
could you show me how you do that with the the button clicks (prev, next).
ok my code perhaps
https://code.sololearn.com/WemEIXTm4DxW/?ref=app
thx
+ 1
Ginfio sure, i'll shoot a public youtube video to explain, if you don't mind