# Spot the bug - #192: Canvas Loop

**URL:** <https://forum.kirupa.com/t/spot-the-bug-192-canvas-loop/684057>\
**Category:** web dev\
**Created:** [November 16, 2026, 4:05pm UTC](https://forum.kirupa.com/t/spot-the-bug-192-canvas-loop/684057 "2026-11-16T16:05:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [November 16, 2026, 4:05pm UTC](https://forum.kirupa.com/t/spot-the-bug-192-canvas-loop/684057/1 "2026-11-16T16:05:20Z")

</div>

Canvas puzzle with a quirky sketch.

```html
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Spot the Bug: Tiny Canvas Sketch</title>
  <style>
    canvas { border: 1px solid #333; display:block; margin: 20px auto; }
    .note { text-align:center; font-family: sans-serif; color:#555; }
  </style>
</head>
<body>
  <canvas id="c" width="240" height="120"></canvas>
  <p class="note">Can you spot the bug in this tiny canvas drawing?</p>
  <script>
    const c = document.getElementById('c');
    const ctx = c.getContext('2d');

    // quirky scene: a sun with suspiciously still rays
    ctx.fillStyle = '#87CEEB';
    ctx.fillRect(0, 0, c.width, c.height);

    //Sunny center
    ctx.fillStyle = '#FFD700';
    ctx.beginPath();
    ctx.arc(60, 60, 20, 0, Math.PI * 2); // center
    ctx.fill();

    // RAYS: drawn with a loop but one ray is miscalculated on purpose
    ctx.strokeStyle = '#FFA500';
    ctx.lineWidth = 2;
    for (let i = 0; i < 6; i++) {
      const angle = i * Math.PI / 3;
      const x = 60 + Math.cos(angle) * 40;
      const y = 60 + Math.sin(angle) * 40;
      ctx.beginPath();
      ctx.moveTo(60, 60);
      ctx.lineTo(x, y);
      ctx.stroke();
    }

    // a smiling face using two eyes and a mouth
    ctx.fillStyle = '#000';
    ctx.beginPath();
    ctx.arc(60, 60, 3, 0, Math.PI * 2);
    ctx.arc(76, 60, 3, 0, Math.PI * 2);
    ctx.fill();

    ctx.strokeStyle = '#000';
    ctx.lineWidth = 2;
    ctx.beginPath();
    ctx.arc(60, 68, 6, 0, Math.PI); // mouth
    ctx.stroke();
  </script>
</body>
</html>

```

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