Doubt about how to write functions on mouse events vs keyboard events

link: https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/dom-javascript-events/lessons/dom-events/exercises/key-events

doubt about how to write functions on mouse events vs keyboard events

the lesson on the link above do not allow me to write a function like we were told on the previous lession.

Why cant I write a key down event like this:

ball.keydown = function(){

  ball.style.bottom = '250px';

}

(or documento.style.bottom…

This format would be valid, as stated on the previous lesson, if it were mouse events.

When you are writing an event in this format, you need to remember to add the “on” to the beginning. When using event listeners (as I think comes a little later in that course) then that format is fine, however when written like that it should be element.onkeydown as in the previous exercise it should have been element.onclick.

1 Like