When I click on button 1, it starts at image 1 because the counter is set to 0. Clicking on button 2 takes me to image 4 with a counter value of 3, while clicking on button 3 leads to image 7 with a counter value of 6.
The process should also work in reverse - starting from image 7 when button 3 is clicked, moving to image 4 when button 2 is clicked, and then back to image 1 when button 1 is clicked.
I have three buttons that correspond to different positions: 0 for button 1, 1 for button 2, and 2 for button 3. The counter increments by 3 each time a higher-positioned button is clicked.
My goal is to ensure that clicking on button 1 sets the counter to 0, clicking on button 2 sets it to 3, and clicking on button 3 sets it to 6. The counter increases by three for higher-positioned buttons and decreases by three for lower-positioned ones.
I am using variables i for button position and img for the current image number comparison. Here's an example using conditional statements:
let counter = 0;
if(i == 0){
// setting counter to 0
img[counter].style.background = "#acc2fa";
}else if(i == 1){
counter = 3;
img[counter].style.background = "#084cf6";
}else if(i == 2){
counter = 6;
img[counter].style.background = "#031a53";
}
I attempted to simplify the code but encountered issues when the condition is equal to 0. Here's what I tried:
if(i != 0 || (img % 3) == 0){
counter = counter + 3;
}
If you have any suggestions on how I could address this problem, please let me know. Thank you!