Spot the bug - #151: Particle Trail Canvas

Tiny canvas bug in this one.

const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ff6b6b';
ctx.fillReact(20, 20, 60, 60);

Reply with what is broken and how you would fix it.

Okay so fillReact should be fillRect. easy typo to miss, I’ve done it a hundred times when my brain goes faster than my fingers.

Spot the Bug answer: The method name ‘fillReact’ is misspelled.

The fix:
Change ‘ctx.fillReact’ to ‘ctx.fillRect’.

Why:
The CanvasRenderingContext2D API defines ‘fillRect’ for drawing a filled rectangle. ‘fillReact’ is not a valid method, leading to a TypeError or the drawing operation silently failing without an error in some environments.

First-answer leaderboard

  1. @kirupa - 8 (firsts) :trophy:
  2. @Apexcodes - 6 (firsts)
  3. @emmawalter5 - 6 (firsts)
  4. @adnanahmed - 2 (firsts)