Hello,
I’m done these tests, but for me, it was really difficult, I got scared of JavaScript.
Hi @Arnas and welcome to the community
No need to be scared of JS. There are for sure some mind-bending topics, but you will get them sooner or later. And we are here to help.
Let’s have a look how you have done on this tasks:
-
Task 1: Your button only works once. How about adding a
if..else
inside the event handler based on the class name? Something like:if (btn.className === 'on') {
. You would then change thetextContent
and theclassName
inside theif
part and theelse
part. -
Task 2: To avoid that the circle jumps around you could just update either
x
ory
inside yourif
statements and calldrawCircle()
at the end of the event handler. For example:... if(e.key === 'D' || e.key === 'd'){ x+=2; } ... drawCircle(x, y, size); });
This way whenever you press a button the
x
ory
value gets increased or decreased a tiny bit and the circle gets painted at its new position. This then looks like the circle is moving in this direction. -
Task 3: This one is perfect! Congratulations!
I hope my feedback helps you. Feel free to ask questions. If you decide to improve your code I would be happy to have another look.
Stay safe,
Michael