Help needed with Test Your Skills: Arrays 3;

Functions 2 test review?

const canvas = document.querySelector(‘canvas’);

  const ctx = canvas.getContext('2d');

  const x1 = 50;

  const y1 = 60;

  const width = 100;

  const height = 75;

  const color = 'blue';

  // Add your code here

  const drowRect = function() {

    ctx.clearRect(x1, y1, width, height);

    ctx.fillStyle = color;

    ctx.fillRect(x1, y1, width, height);

  }

  drowRect();

const section2 = document.querySelector(’.preview-function2’);

Nice work. This is also correct. :+1:

1 Like

Hello @mikoMK can you look at my task about Events number 3?
Codepan link: https://codepen.io/milanodituti/pen/yLExRNb

Thanks in advance :slight_smile:

While your solution works, we can heavily simplify it.
Have a look at the content of each block. Your are doing the same thing every time. Since we are relying on the data-color attribute of each button, it isn’t necessary to test for the textContent.
Can you see how to make the code simpler?

Yes, I can see how to simplify code heavily and I must admit that I tried that solution and it did not work…
Because of that, I chused a different approach with much more code.
Link codepan solution :arrow_forward:

Hard to say what went wrong the first time, but I can confirm that your new solution correctly works and is perfectly coded. :ok_hand:

1 Like