They are shown when you run the tests. Until then they appear as a hidden requirement.
Build a shopping cart: add products, change their quantities and apply a coupon, with a subtotal, a discount and a total. You practice immutable updates of a list of objects and values derived from state.
Add buttons, the cart lines with − and +, the coupon form and the totals.aria-labels (Add T-shirt, Increase T-shirt, Decrease T-shirt, Quantity of T-shirt, Coupon code), the texts (Your cart is empty, Subtotal: $…, Discount: −$…, Total: $…, Invalid coupon) and the roles: the tests use them.Your cart is empty and Total: $0.00.Add puts the product in the cart with quantity 1; adding a product that is already there increases its quantity instead of adding another line.+ and − change the quantity of a line; when it goes below 1, the line is removed.$12.99).Apply with the code SAVE10 gives 10% off the subtotal: you see Discount: −$… and the total is the subtotal minus the discount. The discount is rounded to cents.Invalid coupon in an element with role="alert", and there is no discount.$12.99, and Total: $12.99.SAVE10 → Discount: −$1.30 and Total: $11.69.+ on the mug → $25.98 on its line.The cart is a list of { id, name, price, quantity }: add, change and remove lines with map, filter and spread, never by changing the objects.
Store which coupon is applied, not how much it takes off: the discount comes from the current subtotal.
toFixed(2) turns a number into text with two decimals.
The console is empty
Run your code with Ctrl+S
This console starts empty every time the preview loads. The browser's DevTools console keeps the messages with Preserve log.