Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day March 13, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    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();
    JavaScript

    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?