0
How do i reset a global variable
https://code.sololearn.com/WR4z4HaxoZxa/?ref=app ..take a look at this code. The problem: I have two buttons which i use to move the content of a div, each time i click the button i add 220px to the global variable and use it to move the content but when i click on any of the button the 220px seems to be saved in that variable so when i click on the other button instead of moving it from 0 to 220px it moves it 440px(meaning the variable had the previous 220px saved in it). pls suggest me a solution in pure js
1 Odpowiedź
+ 5
Create two position trackers instead of using the same one. For your function, edit it so that it doesn't read the global variable directly, and instead takes the position as a parameter.