Assessment wanted for Functions skills test by Dinesh

Hi :wave:,
I have recently finished functions skill tests and I want a review for my codes. Any suggestions are welcome. Here are the links for code pen and task,
Functions 1 & task link
Functions 2 & task link
Functions 3 & task link
Functions 4 & task link

Thank you in Advance,
Dinesh

1 Like

Hi @Dinesh_Sake

Well done! Here are my comments:

  • Task 1: :white_check_mark: Correct.
  • Task 2: :white_check_mark: Correct. You clear exactly the area where the blue rectangle is. This works for this specific exercise. Normally when you’re having a draw() function, you would start by clearing the whole canvas: ctx.clearRect(0, 0, canvas.width, canvas.height);
  • Task 3: :warning: Mostly correct. The exercise ask for the random() function to have two generic bounds. It should look like this:
    function random(min, max) {
      ...
      return num;
    }
    
    You need to implement the function so that you can use names[random(0, array.length)] to get a random name from the array.
  • Task 4: :white_check_mark: Correct.

Please tell me if you need more help with the task 3. :slightly_smiling_face:

Happy coding,
Michael

1 Like

Hi Sir, I’ve made changes according to your comments. Here you can take a look yourself, Task 2
Task 3

1 Like

Wow. That was fast :wink:

Task 2 is now correct.

For task 3:
I would recommend to define the max parameter as just a number (like min) and use random(0, array.length) to call it. This way we just have to work with numbers inside the random() function.
The other thing is: Your formula isn’t quite right. You subtract min and immediately add it back. So the min value doesn’t have an effect. random(3,8) would still give a number between 0 and 7. + min needs to be outside Math.floor() and then it should work.

1 Like

Okay Sir, here is the corrected task.

1 Like

Great work.
Now it’s perfect. :+1:

1 Like