79723276

Date: 2025-08-02 10:22:52
Score: 1.5
Natty:
Report link

The issue is with how you're setting the context.fillStyle. You're using a template string inside single quotes, which doesn't interpolate the variables. This makes the color string invalid, so the canvas defaults to black.

Incorrect: context.fillStyle = 'rgba(${myColour[0]}, ${myColour[1]}, ${myColour[2]}, ${myColour[3]})';

This literally sets the string "rgba(${myColour[0]}, ...)" which is not a valid CSS color.

Fix: Use backticks instead of single quotes to enable string interpolation:

context.fillStyle = `rgba(${myColour[0]}, ${myColour[1]}, ${myColour[2]}, ${myColour[3] ?? 1})`;

You can also use destructuring:

const [r, g, b, a = 1] = myColour;

context.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`;

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Rajanandini Godisela