The situation
You have just joined the engineering team at a small online shop that sells stationery and desk accessories. The cart page is live, and this week support has received several complaints that the total at checkout doesn't add up.
One customer has 3 notebooks ($4.50 each), 1 pen set ($12.00) and 2 desk lamps ($29.99 each). Their items are worth $85.48, but the cart shows $46.49. Every under-charged order loses the shop money, so this is your first priority.
"The total at checkout is lower than what I added to my cart."
Your tasks
Task 1: Fix the cart total
- Find out why
cartTotal in src/utils/cart.js returns the wrong number, and fix it. - Each line costs its price times its quantity. The total is the sum of all lines.
- Make every test in
src/utils/cart.test.js pass, and check that the preview shows Total: $85.48. - The item lines show the price of one unit (for example
Desk lamp x2: $29.99). That is intended and doesn't need to change.
Task 2: Review your own change
Above your fix, add a short comment saying what else you would check before shipping it. Think about unusual carts a real customer could have.
Project files
package.json
public/
index.html
src/
index.js
index.css
App.js
App.css
components/
CartSummary.js
utils/
cart.js
cart.test.jssrc/App.js: the cart page. It holds the sample cart (three items) and renders the summary.src/App.css: one custom rule that keeps price digits lined up. Everything else is styled with Tailwind classes.src/components/CartSummary.js: lists each item and shows the total, using the helpers in src/utils/cart.js.src/utils/cart.js: the cart maths. formatPrice turns a number into $0.00 text and cartTotal adds up the cart.src/utils/cart.test.js: the tests for src/utils/cart.js.package.json, public/index.html, src/index.js and src/index.css: the standard React app setup. src/index.js starts the app and loads Tailwind CSS, and src/index.css holds the global styles. You don't need to change these.
How to check your work
- Tests: press ▶ Run tests next to the Tests heading in the bottom panel. They don't re-run on their own, so run them again after each change. PASS means every visible test passed.
- Preview: the bottom-left panel shows the running app and rebuilds as you type. Use Open in new tab above it, or Copy link and paste it into a new tab, to see it full size. That tab follows your edits.
- Your work is saved in this browser. Reset (top right) puts the starting code back.