+ 8
This code isn't working..[closed]
Sry if this isn't right to post here.. But my code written in JavaScript isn't working.. How i want it to work is.. The box should go on moving from left to right.. But it stays at the start! Is this because of the setInterval function? How can i fix it? https://code.sololearn.com/W7sIA3CuvCwE/?ref=app
7 Antworten
+ 1
look here: https://code.sololearn.com/WudFQ8s5H8Zt
+ 4
@Uria
I tried all that.. I added clearInterval(t2) in moveR's else statement so that it starts moving right.. But when is reaches 150px, since t2 is 'off' it again stays there.. Is there a function to turn the interval 'on' again?
+ 4
@uria
I didn't really got what you said.. The vars are already out of the moveR/L functions(on the top)
+ 4
Niceeeeeeeee... You're the best!!! Now I'll try to move it fully ( L, R, up, down) :)
Thanx again!
+ 1
remove t2, and clear t1 when it gets to pos=150.
As it is now it moves in both directions at the same speed&time, so basically not moving.
+ 1
Glad I could help :)
0
@yash
You can define the timers vars (t1,t2) outside of the moveL/R functions, then you can use clearInterval() or reassign it from those functions when the if condition is true.
Note that you need to create both t1,t2 outside the moveL/R, then to initiate only the t1 so it starts to move.
Let me know how it goes :)