Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day March 20, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    What does the following program do?

    let elem;
    let ball;
    
    function main() {
        keyDownMethod(keyDown);
        mouseMoveMethod(select);
        addCircle();
    }
    
    function keyDown(e) {
        if (e.key == "g") {
            ball.setColor(Randomizer.nextColor());
        }
    }
    
    function select(e) {
        ball = getElementAt(e.getX(), e.getY());
    }
    
    function addCircle() {
        let ball = new Circle(40);
        ball.setPosition(getWidth() / 2 - 100, getHeight() / 2);
        add(ball);
    
        let ball = new Circle(40);
        ball.setPosition(getWidth() / 2 + 100, getHeight() / 2);
        add(ball);
    }
    
    main();
    JavaScript