Menu
Coddy logo textTech

Recap challenge

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 34 of 56.

challenge icon

Challenge

You're given a ShoppingCart class. Your task is to add:

  1. Static properties:
    • taxRate set to 0.08 (8% tax)
    • currency set to "USD"
  2. Static method:
    • calculateTax(amount) that returns amount * 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