Function 2: Unable to change color

I’m struggling with this challenge. I can’t seem to get the color of the rectangle to change from the default ‘black’ to ‘blue’. Also, am I using the .fillRect method correctly?


Hello @Leo_S

you need to set the color first

ctx.fillStyle = color;
  ctx.fillRect(x, y, width, height);

cause your code make it draw the rectangle then set the color to blue

one more thing you do not need the last ctx.fill(); line use this one when you fill a path as fillrect draw the rectangle and fill it also

hope that help and have a nice day :slight_smile:

hope that help and have a nice day

That does the trick. Thanks a lot for your advice @justsomeone!

you very welcome @Leo_S