Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
We’ve set up animate to be called every time a key is pressed down on the keyboard:
animate
function main() { keyDownMethod(animate); } function animate(e) { ball.move(5, 5); } main();
How can we set up animate so that it will only move the ball if the up arrow on the keyboard is pressed?
function animate(e) { if (e.isUp()) { ball.move(5, 5); } }
function animate(e) { if (e.UP) { ball.move(5, 5); } }
function animate(e) { if (e.key == "ArrowUp") { ball.move(5, 5); } }
Keep animate the same and change main to
main
function main() { keyUpMethod(animate); }