From 7641e79e2ab8eb2d4e2be01a365e86c7028fb2ac Mon Sep 17 00:00:00 2001 From: kavya sri Date: Mon, 5 May 2025 12:18:31 -0500 Subject: [PATCH] produt and cart --- classes/Cart.js | 17 +++++++++++++++++ classes/Product.js | 14 ++++++++++++++ index.js | 2 -- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..267aa0b 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,17 @@ +class Cart{ + constructor(){ + this.products = []; + this.total = 0; + } + + addProduct(product){ + this.product.push(product); + this.total += product.price; + } + removeProduct(index){ + if(index >= 0 && index < this.products.length){ + this.total -= this.products[index].price; + this.products.splice(index, 1); + } + } +} \ No newline at end of file diff --git a/classes/Product.js b/classes/Product.js index e69de29..ebb138d 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -0,0 +1,14 @@ +class Product{ + constructor(name, price, description){ + this.name = name; + this.price = price; + this.description = description; + this.instock = true; + display() { + resturn`Name: ${this.name}, Price: $${this.price}, Description: ${this.description}`; + } + } + +} + + diff --git a/index.js b/index.js index efad601..445e86b 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,6 @@ - - // DO NOT EDIT BELOW THIS LINE try { module.exports = {