thecodezone.
The Code Zone
← Back to the Developer Playbook

Code Zone Bug Lab / Episode 02

The Cart That Can’t Add

A $15 cart becomes $105 at checkout. Investigate JavaScript values, test a hypothesis, and fix a beginner bug ticket in a live coding playground.

DEV-145 · Beginner JavaScript15–20 minutesNo setup or account required
Cartoon Rob checks a $10 notebook and $5 sticker pack with a $15 subtotal, sees $105 at checkout, and exclaims that it should be $15.
Observe the problem. Follow the evidence.

Your sprint ticket · In progress · DEV-145

Checkout shows $105 for a $15 cart.

Customer report: A $10 notebook and $5 sticker pack total $15 in the cart, but $105 at checkout.

Steps to reproduce

  1. Keep prices at 10 and 5.
  2. Click Go to checkout.
  3. Compare the cart subtotal, checkout total, and Console.

Shipping, tax, quantities, and redesign are separate tickets.

Acceptance criteria

  • Prices 10 and 5 produce a checkout total of $15.00.
  • Prices 12 and 3 produce $15.00; prices 0 and 5 produce $5.00.
  • Prices 2.50 and 1.25 produce $3.75.
  • Changing either price and checking out again uses the latest values.
  • The cart subtotal and checkout total agree, with no JavaScript errors.

Learning demo only. No account changes, email, purchases, or payments occur.

Reproduce → inspect → hypothesize → verify

Take the ticket.

Click Go to checkout before editing. Read the logged prices and their types in the Console. Inspect calculateCheckoutTotal in the JavaScript tab and the price inputs in HTML. CSS is supplied for the preview and hidden from the editor. Say your hypothesis, make a focused change, then choose Check challenge to test every case in the ticket. Run code refreshes the cart without grading it. Edits update the preview automatically. On a phone, the cart preview appears below the code.

Checking account and saved lab work…

Sign in to sync across devices

Loading the JavaScript and HTML editor…

Pass the checks or make three attempts to unlock an explained example.

Ready to test? Choose “Check challenge” after investigating.

    Open starter in a separate tab

    Code and prediction notes recover in this browser and sync when signed in. Instructor examples stay separate. Reset replaces code, not prediction notes.

    One possible solution

    Compare this approach with your own. Opening it does not change your code or mark the exercise complete.

    Input value properties are strings. The starter joins "10" and "5" into "105". Convert both operands before the addition:

    Number(notebookPrice + stickerPrice) still gives 105: joining already happened. Formatting the final result with toFixed(2) only changes its display. It does not repair the calculation.

    Retest all ticket cases, including decimals and a second checkout after editing prices. This is a small learning demo; production money calculations typically use integer minor units or a decimal library.

    Convert before adding
    checkout.jsjavascript · example
    return Number(notebookPrice) + Number(stickerPrice);

    Try first. Reveal one clue at a time.

    Need a lead?

    1. What kind of values are these?

    Look at the Console after checkout. The values look like prices, but what does typeof report? Does an input with type="number" necessarily give JavaScript a number through its value property?

    2. One symbol, two jobs.

    In JavaScript, + can add numbers or join strings. Compare 10 + 5 with "10" + "5". Which behavior matches your evidence?

    3. Convert before calculating.

    Try converting each input value with Number before adding. Converting the already joined result is too late. Keep reading the inputs inside the function so the next checkout uses updated prices.

    Your lab report

    Show your reasoning.

    “I expected… I observed… The console showed… My hypothesis was… I changed… I verified…”

    Use Check challenge for automated behavior checks. Passing checks are useful evidence, not a complete code review.

    Give others room to investigate: label solutions as spoilers.

    Share your lab report on SKOOL (new tab) ↗