Ibeh_John
(Ibeh John)
October 12, 2022, 9:29am
1
The test requires that I move the circle around the canvas using keys w,a,s,d .I tried using the keydown event, with a function that updates the x and y co-ordinates, but it does not work.
This is a link to my code: https://campsell.w3spaces.com/saved-from-Tryit-2022-10-12.html
This is the link to the task: Test your skills: Events - Learn web development | MDN (mozilla.org)
Thank you in anticipation
mikoMK
(Michael Koch)
October 12, 2022, 11:20am
2
Hi @Ibeh_John and welcome to the community
Here are some hints:
Having addEventListener
inside an if
condition doesn’t really make sense.
Your canvas
listener should call move
when a key is pressed.
After updating x
or y
you need to call the draw function inside move
to see the changes.
I hope this will get you further. Please ask if you need more help.
Have a nice day,
Michael