Assessment wanted for Events Skills Test 1/2/3

Hello,
I’m done these tests, but for me, it was really difficult, I got scared of JavaScript. :smiley: :grimacing:

Test your skills: Events

Event 1
Event 2
Event 3

Hi @Arnas and welcome to the community :wave:

No need to be scared of JS. :grin: There are for sure some mind-bending topics, but you will get them sooner or later. And we are here to help. :slightly_smiling_face:

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 the textContent and the className inside the if part and the else part.

  • Task 2: To avoid that the circle jumps around you could just update either x or y inside your if statements and call drawCircle() 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 or y 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! :medal_sports:

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