Review required for events 2 skill check

Hi everybody.

Who can say whether the task is understood correctly and whether the solution corresponds.

My solution to the second event-related task.

A link to the actual task.

Thank you all very much.

Thanks to the gamers, they suggested what “WASD” is. The code has been corrected.

1 Like

Excellent work, @petrushya!

That’s a nice touch with the range input. :heart_eyes:
You could make the code a bit simpler by changing `${e.key}` to e.key and use a variable for e.key.toLowerCase() outside the if statement. Do you know what I mean?

Michael

Hi @mikoMK!

About backtick characters. I had to rethink the article “Element: keydown event” and try out the examples live, probably the “keyCode” looks better.

The “switch” is shorter, of course, but the boundaries of the block still need to be marked…
The code has been corrected.

Good luck.
Pyotr.

I don’t recommend using keyCode. It’s deprecated: KeyboardEvent.keyCode.
Maybe you could open an issue on the MDN GitHub project. The example on “Element: keydown event” shouldn’t use deprecated properties.

Another possibility would be to use KeyboardEvent.code. It’s based on the physical positions of the key on an American keyboard and ignores the keyboard layout. For this exercise it has the advantage that the WASD position is still the same on another keyboard layout.
For example at the position of the “w” key is the “z” key on French keyboards. When using e.code === 'KeyW' a French user can press his “z” key and the ball would still go up. On the other hand when using e.key === 'w' a French user needs to press his “w” key which is at a completely different spot.

I also thought about recommending “switch”, but because of the additional condition you also mentioned, I’m not sure if it’s really simpler.

Michael

Hi @mikoMK.

Thanks for the hints. I leave the problem with the deprecated property to your discretion. :slightly_smiling_face:

Good luck.
Pyotr

1 Like