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
All of the following programs draw a rectangle on the canvas. Select the option that does the following:
function main(){ mouseDragMethod(paint); } function paint(e){ let rect = new Rectangle(50, 50); rect.setColor(Randomizer.nextColor()); rect.setPosition(e.getX() - rect.getWidth(), e.getY() - rect.getHeight()); add(rect); } main();
function main(){ mouseClickedMethod(paint); } function paint(e){ let rect = new Rectangle(50, 50); rect.setColor(Randomizer.nextColor()); rect.setPosition(e.getX() - 25, e.getY() - 25); add(rect); } main();
function main(){ mouseDragMethod(paint); } function paint(e){ let rect = new Rectangle(50, 50); rect.setColor(Randomizer.nextColor()); rect.setPosition(e.getX() + rect.getWidth(), e.getY() + rect.getHeight()); add(rect); } main();
function main(){ mouseMoveMethod(paint); } function paint(e){ let rect = new Rectangle(50, 50); rect.setColor(Randomizer.nextColor()); rect.setPosition(e.getX() - rect.getWidth() / 2, e.getY() - rect.getWidth() / 2); add(rect); } main();