Back to Labs
Debug hunt

Fix the checkout total bug

Read the trace, fix the function, then run the tests.

Topic intro

Good debugging starts with a failing test. Fix the smallest mistake, then rerun the tests to prove the change works.

How to find the answer

Start with the failing tests. Look for missing defaults and data type issues. Change the smallest amount of code to pass all cases.

Editor

Failing trace


TypeError: Cannot read properties of undefined (reading 'qty')
  at calculateTotal (cart.ts:2:55)
  at checkout (checkout.ts:18:13)
  at run (test.ts:7:3)
Remember to handle missing qty and string prices.

Test results

Run tests to see results.

Fix summary

Write a short note about the bug and the fix.