Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

JavaScript Question of the Day March 12, 2025

  1. Incorrect Correct No Answer was selected Invalid Answer

    Consider the following code:

    let player;
    
    function main() {
        player = initPlayer(200, 200, 20, 20, "yellow");
        keyDownMethod(keyDown);
    }
    
    function keyDown(e) {
        if (e.key == "ArrowLeft") {
            player.move(-15, 0);
        } else if (e.key == "ArrowRight") {
            player.move(15, 0);
        } else if (e.key == "ArrowUp") {
            player.move(0, -15);
        } else if (e.key == "ArrowDown") {
            player.move(0, 15);
        }
    }
    
    function initPlayer(x, y, w, h, color) {
        let rect = new Rectangle(w, h);
        rect.setPosition(x, y);
        rect.setColor(color);
        add(rect);
    
        return rect;
    }
    
    main();
    JavaScript

    what would the new coordinates of the player be if they press the left arrow key twice?