Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day March 31, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    Consider the following program:

    let rect;
    const WIDTH = 50;
    const HEIGHT = 50;
    
    function main() {
        drawRects();
    }
    
    function drawRects() {
        for (let i = 0; i < 20; i++) {
            let randX = Randomizer.nextInt(0, getWidth());
            let randY = Randomizer.nextInt(0, getHeight());
            if (i % 2 == 0) {
                createRect(randX, randY, WIDTH + i, HEIGHT + i, "black");
            }
        }
    }
    
    function createRect(x, y, width, height, color) {
        rect = new Rectangle(width, height);
        rect.setPosition(x, y);
        rect.setColor(color);
        add(rect);
        return rect;
    }
    
    main();
    JavaScript

    How many rectangles are drawn on the canvas?