Congratulations, you made it to the end of the course! Marta’s label maker now runs in JavaScript. For order 1042, shipping-label.js picks the Leeds billing address, since the shipping address is null, and prints “no phone” for a guest checkout. Its label quotes £3.20 for Britain, counts two parcels, keeps the insured value at 0, and lists the tags as ["fragile", "gift"], exactly as shipping_label.py does.
In the last exercise, you added the remote-area surcharge and the price for orders that aren’t gifts, so order 1043’s label shows £7.70 in postage and a price of £18.50. In this course, you learned how to:
- Build an object literal with bare keys and read its properties with dot notation when you know the key and with bracket notation when the key comes from data, as in
RATES[country] - Put a key held in a variable into a literal with
[HOME_COUNTRY]: 3.2, since a bare key uses its literal name - List keys, values, and pairs with
Object.keys(),Object.values(), andObject.entries(), and pick aMapwhen keys must stay numbers - Give a value that’s
undefinedornulla default with??, so order 1042 keeps its insured value of0, and remember that unlike.get(),??replaces a storednulltoo - Reach into a nested object that may be missing with
?., as inorder.customer?.phone ?? "no phone" - Drop repeated tags with
new Set(), check membership with.has(), and spread a Set back into an array with[...tags] - Read pasted JSON with
JSON.parse()and turn the label into indented JSON text withJSON.stringify(label, null, 2)
Keep Asking What Could Be Missing
Python tells you loudly when a key isn’t there. order["phone"] raises a KeyError. JavaScript stays quiet. A missing key reads as undefined, and it travels on until something fails further down or it lands on a label.