Ask coding questions

← Back to all posts
Why aren't the movements working?
zakdakidd (15)

I need help, I thought I was doing everything right, but the movements of the ball aren't working.

Answered by xxpertHacker (871) [earned 5 cycles]
View Answer
Comments
hotnewtop
xxpertHacker (871)

Among the errors, setInterval should be passed interval, not "interval".

zakdakidd (15)

Thanks, I realize that was wrong along with saying keydown instead of keyup. @xxpertHacker

OmN3xin (51)

There is a lot of reasons your movement isn't working, change if(event.key==="Arrowleft") to if(event.key == "ArrowLeft"), change var interval into var interval = null;, change if(event.key==="ArrorwRight)" into if(event.key == "ArrowRight"). this should work :)

zakdakidd (15)

Yeah, I changed that all but it still doesn't seem to work. The interval thing was a biggie, but I keep finding small errors too. I'm not sure why you use two equal signs when you do if(event.key == "Arrowleft") Please explain thx
@OmN3xin

xxpertHacker (871)

@zakdakidd Regarding (==) vs (===), refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness.

(==) performs type coercion, whereas (===) doesn't.
Usually type coercion for equality is unexpected or otherwise unwanted.