Learn Intermediate OOP by Building a Platformer Game - Step 59

Tell us what’s happening:

My brain hurts. I don’t understand what I am missing. The error I get is:

You need to add an addEventListener to the global window object.

Your code so far

window.addEventListener('keydown', event => {
    const { key } = event;
});

Your browser information:

User Agent is: Chrome

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 59

"…uses the destructuring assignment to get the key property from the event object → in the event listener parameter ← "

You are currently doing the destructuring in a separate line of code in the handler function. Rather, you want to do in in the parameter being passed into the handler.

Thank you!!! I really needed to take a break :sweat_smile:

the instructions/wording on this particular task…God help us :sweat_smile:
#struggles

3 Likes

yeah! I guess the point is to check whether we’re reading carefully… which I clearly failed miserably! lol… anyways, problem solved!

1 Like

I don’t understand what is wrong. Can someone explain this to me ?

You need to add an event listener to the global window object and pass the value attached to key in the event object to the callback function through destructuring assignment

window.addEventListener('keydown', (/*Destruct. Assign.*/) => { 
});

remember that the event object is assigned to your parameter automatically. You don’t need an equal sign, just the curly braces and the key(s) you want.

2 Likes

the event object is assigned to your parameter automatically - this I don’t understand…

The above sentences is described the below sentence.