BeginnerCoder

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.

Want it another way?
Task

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.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with JavaScript Foundations

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.