How do i reset a global variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

24th Jul 2018, 3:10 PM
Ben Acq
Ben Acq - avatar
1 Answer
+ 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.
25th Jul 2018, 10:06 PM
Hatsy Rei
Hatsy Rei - avatar