Lesson 19 — Mini project: cart total
Mini project: a shopping cart
A cart is an array of items, each with a price p and a quantity q. The line total is p * q; the cart total is the sum of all line totals. Many shops also give a discount above a threshold. toFixed(2) formats money with 2 decimals.
(57).toFixed(2) // "57.00"
Why it matters: this is real e-commerce logic — and a place where small bugs cost real money.
Compute the subtotal with reduce (p * q), then apply 10% off when the subtotal is 50 or more.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based JavaScript Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for JavaScript Foundations books — check the publication year so the examples match current versions.
Search Amazon →