Spot the bug - #161: 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.

fillReact should be fillRect. It’s a common typo when you’re typing fast.

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

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

Why:
The CanvasRenderingContext2D API provides a method named ‘fillRect’ for drawing a filled rectangle. ‘fillReact’ is not a valid method, which will cause a TypeError or simply not draw anything without an explicit error in some environments.

First-answer leaderboard

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