Skip to content
WANCODE
BM

Repair the Broken Button

10 minBeginnerDebugging

Customers of Kuih Corner say the Add to cart button "does nothing". The developer who wrote it went on leave. Your job: debug it.

  • Expected: the page starts with Items in cart: 0. Click 3 times → Items in cart: 3.
  • Actual: the button is greyed out, and even when it isn't, the number doesn't change correctly.

Debug like a pro

Fix one bug, click the button, observe, repeat. Add console.log(...) inside the listener to see whether it ever runs. There are bugs in both index.html and script.js.

Constraints

  • Keep the ids add-to-cart and cart-count.
  • The count must show a plain number like 3 — never 0111.

Fix the Add to cart button so every click adds exactly 1 to the cart count (1, 2, 3…). There are three separate bugs — find them all.

Checks

  • The button can be clicked
  • One click adds 1
  • Every click keeps adding 1
Preview

Console output from your code appears here.

Step 1 of 1