Keyboard events learning code (11. Building Interactive Websites with JavaScript)

Does anyone know why the following code does not work for me??
I copied the solution code for the keyboard events as shown below (the commented section depicts my original code)
Tried to run in both Safari and Chrome.

let ball = document.getElementById(‘float-circle’);

// Write your code below

function up(){

ball.style.bottom = ‘250px’;

}

function down(){

ball.style.bottom = ‘50px’;

}

document.addEventListener(‘keydown’, up);

document.addEventListener(‘keyup’, down);

//document.onkeydown = up;

//document.onkeyup = down;

Hi, there is nothing wrong with your code. The fact that it won’t work is weird…Just try to check the link of your main.js in your index.html and if it still doesn’t work try copying all the code and run it in your own code editor.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.