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
Consider The following program:
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 letter ‘j’ is pressed down?
animate
function animate(e) { if (e.isJ()) { ball.move(5, 5); } }
function animate(e) { if (e.j) { ball.move(5, 5); } }
function animate(e) { if (e.key == "j") { ball.move(5, 5); } }
Keep animate the same and change main to
main
function main() { keyDownMethod(animate, "j"); }