Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day March 21, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    In the following program:

    let dx = 5;
    let dy = 5;
    
    let circle;
    
    function main() {
        circle = new Circle(50);
        circle.setPosition(getWidth() / 2, getHeight() / 2);
        keyDownMethod(down);
        add(circle);
    }
    
    function down(e) {
        if (e.key == "a") {
            circle.move(-dx, 0);
        } else if (e.key == "d") {
            circle.move(dx, 0);
        } else if (e.key == "w") {
            circle.move(0, -dy);
        } else if (e.key == "s") {
            circle.move(0, dy);
        } else {
            circle.setColor(Randomizer.nextColor());
        }
    }
    
    main();
    JavaScript

    How can the user move the circle left on the canvas?