diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..7b33dbb 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,18 @@ +class Cart { + constructor(){ + this.products = [] + this.total = 0 +} +addProduct(product) { + this.products.push(product); + this.total += product.price; +} +removeProduct(product) { + const index = this.products.findIndex (p => p === product) + if (index !== -1) { + this.products.splice (index, 1) + this.total -= product.price + } +} +} +module.exports = Cart \ No newline at end of file diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..eb519e3 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -0,0 +1,14 @@ +class Customer { + constructor(name, email, shippingAddress) { + this.name = name; + this.email = email; + this.shippingAddress = shippingAddress; + this.orderHistory = []; // Initializes as an empty array + } + + addToOrderHistory(cart) { + this.orderHistory.push(cart); + } + } + + module.exports = Customer; \ No newline at end of file diff --git a/classes/Product.js b/classes/Product.js index e69de29..b2926ad 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -0,0 +1,13 @@ +class Product { + constructor(name, price, description){ + this.name = name; + this.price = price; + this.description = description; + this.inStock = true; + } + + display(){ + return `Name: ${this.name}, Price: $${this.price}, Description: ${this.description}` + }; + } + module.exports = Product; diff --git a/index.js b/index.js index efad601..d07576c 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,18 @@ // Import Classes Here - - - - - - - - - +const Product = require('./Product'); +// Example of creating a new Product instance and using the display method +let myProduct = new Product('Example Product', 19.99, 'This is a sample description.'); +console.log(myProduct.display()); +// +const Cart = require('./Cart'); +// Example usage +const cart = new Cart(); +console.log(cart); // Initially empty cart +// +const Customer = require('./Customer'); +// Example usage +let customer = new Customer('Jane Doe', 'jane.doe@example.com', '123 Elm Street'); +console.log(customer); // DO NOT EDIT BELOW THIS LINE try {