Recap challenge
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 34 of 56.
Challenge
You're given a ShoppingCart class. Your task is to add:
- Static properties:
taxRateset to0.08(8% tax)currencyset to"USD"
- Static method:
calculateTax(amount)that returnsamount * taxRate
Try it yourself
import { ShoppingCart } from './shoppingCart.js';
// Test code - don't modify
console.log(ShoppingCart.currency); // Should output "USD"
console.log(ShoppingCart.calculateTax(100)); // Should output 8 (100 * 0.08)
const cart = new ShoppingCart();
console.log(cart.addItem(25)); // Should output 25
console.log(cart.addItem(50)); // Should output 75
console.log(ShoppingCart.calculateTax(cart.total)); // Should output 6 (75 * 0.08)
All lessons in Object Oriented Programming
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge