Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day April 4, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    Consider the following program:

    let rect;
    let red = "red";
    let blue = "blue";
    
    function main() {
        drawRect(100, 100, getWidth() / 2, getHeight() / 2, blue);
        setTimer(animation, 100);
    }
    
    function drawRect(width, height, x, y, color) {
        rect = new Rectangle(width, height);
        rect.setPosition(x - width / 2, y);
        rect.setColor(color);
        add(rect);
        return rect;
    }
    
    function animation() {
        rect.setColor(Randomizer.nextColor());
        rect.move(0, 5);
        if (rect.getY() + 100 >= getHeight()) {
            makeRed();
        }
    
        if (rect.getColor() == red) {
            stopAnimation();
        }
    }
    
    function makeRed() {
        rect.setColor(red);
    }
    
    function stopAnimation() {
        stopTimer(animation);
    }
    
    main();
    JavaScript

    What will the color of the rectangle be when the program is finished running?