Canvas puzzle with a quirky sketch.
<!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.