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
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();
Which option below will result in a rectangle being added to the canvas without an error occurring?
Change line 2 to be, let sqr = createSquare(50, 200, 100, "orange"); and line 3 to be changeSquare(sqr);.
let sqr = createSquare(50, 200, 100, "orange");
changeSquare(sqr);
Change line 2 to be, let square = createSquare(50, 200, 100, "orange"); and move it outside of the main() function (to line 1). Then remove the square parameter in the changeSquare() function on line 14.
let square = createSquare(50, 200, 100, "orange");
main()
square
changeSquare()
Both A and B are valid options to fix the program.
Neither A or B will fix the program.