Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day April 9, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    The following program results in an error when run:

    function main() {
        createSquare(50, 200, 100, "orange");
        changeSquare();
    }
    
    function createSquare(size, x, y, color) {
        let rect = new Rectangle(size, size);
        rect.setPosition(x, y);
        rect.setColor(color);
        add(rect);
        return(rect);
    }
    
    function changeSquare(square) {
        let size = square.getWidth() + 50;
        square.setSize(size, size);
        square.setColor("red");
    }
    
    main();
    JavaScript

    Which option below will result in a rectangle being added to the canvas without an error occurring?