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:
let ball; function main() { ball = new Circle(100); ball.setPosition(getWidth() / 2, getHeight() / 2); ball.setColor("red"); add(ball); keyDown(); } function keyDown() { keyDownMethod(changeColor); } function changeColor(e) { if (e.key == "a") { ball.setColor("orange"); } else if (e.key == "b") { ball.setColor("black"); } } main();
Once the program is running, how many times will we be able to use the key event handler and change the color of the ball?
One time since the function keyDown is only called once
keyDown
Two times
Unlimited times as long as the program is running
This code does not allow us to change the color of the ball