Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
What is outputted to the canvas when the following program is run?
function main() { let square = createSquare(50, 200, 100, "orange"); changeSquare(square); } 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();
Nothing, because the square variable on line 2 needs to be created as a global variable for this program to work properly.
square
Nothing, because you can’t use the same variable name “square” in both the main() and changeSquare() functions.
main()
changeSquare()
An orange square of size 50.
A red square of size 100.