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 does the following program do?
let elem; let ball; function main() { keyDownMethod(keyDown); mouseMoveMethod(select); addCircle(); } function keyDown(e) { if (e.key == "g") { ball.setColor(Randomizer.nextColor()); } } function select(e) { ball = getElementAt(e.getX(), e.getY()); } function addCircle() { let ball = new Circle(40); ball.setPosition(getWidth() / 2 - 100, getHeight() / 2); add(ball); let ball = new Circle(40); ball.setPosition(getWidth() / 2 + 100, getHeight() / 2); add(ball); } main();
The program adds two circles to the canvas and changes both of their colors whenever the user presses the key g
g
The program adds two circles to the canvas and changes the color of one of the circles whenever the user presses the key g while hovering over the circle
The program adds two circles to the canvas and changes both of their positions in the direction of the mouse cursor whenever the user presses the key g
The program adds a circle with a random color whenever the user presses the key g