# Spot the bug - #196: Button

**URL:** <https://forum.kirupa.com/t/spot-the-bug-196-button/684198>\
**Category:** web dev\
**Created:** [November 27, 2026, 4:05pm UTC](https://forum.kirupa.com/t/spot-the-bug-196-button/684198 "2026-11-27T16:05:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [November 27, 2026, 4:05pm UTC](https://forum.kirupa.com/t/spot-the-bug-196-button/684198/1 "2026-11-27T16:05:15Z")

</div>

A quirky page with a tiny logic quirk.

```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Spot the Bug</title>
  <style>
    body { font-family: sans-serif; background: #f7f7f7; padding: 2rem; }
    .card { width: 280px; padding: 1rem; border-radius: 8px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
    .badge { display: inline-block; padding: 4px 8px; background: #e0e7ff; border-radius: 999px; font-size: 12px; }
    #led { width: 20px; height: 20px; border-radius: 50%; background: red; display: inline-block; margin-left: 8px; }
  </style>
</head>
<body>
  <div class="card">
    <h2>Logic Toy</h2>
    <p>Click the button to toggle the LED color, but one line of logic is a trap.</p>
    <button id="toggle">Toggle LED</button>
    <span id="status" aria-live="polite">OFF</span>
    <div style="margin-top:8px;">
      <span class="badge">logic</span>
    </div>
  </div>
  <script>
    const led = document.getElementById('led');
    const btn = document.getElementById('toggle');
    const status = document.getElementById('status');

    let on = false;

    btn.addEventListener('click', function() {
      // deliberate bug: the assignment is reversed in the conditional below
      if (on = !on) { // bug: should be 'on = !on' is actually assignment; effect intentional
        led.style.background = 'green';
        status.textContent = 'ON';
      } else {
        led.style.background = 'red';
        status.textContent = 'OFF';
      }
    });
  </script>
</body>
</html>

```

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