Question: please use proper es6 syntax JavaScript , use let and const do not use html, only modern JavaScript WRITE THIS IN JAVASCRIPT ES6 SYNTAX create
please use proper es6 syntax JavaScript, use "let" and "const" do not use html, only modern JavaScript
WRITE THIS IN JAVASCRIPT ES6 SYNTAX
create a class that lets you create a record of shopping products - names products - amount of products - cost of products
each shopping entry must look like this {product:'product name' amount:1, cost:$200 }
this class should allow for dot chaining notation the constructor should accept an array of objects or if nothing is passed - defaults to an empty array
buyProduct(object): accepts an object and adds a product to the record. use destructuring for the grocery object. default should be 1 for quantity. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)
deleteProduct(string): accepts a case insensitive string, removes a shopping product by name if the quantity is 1, else it subtracts the amount by 1
sumPrice(string,number): accepts a case insensitive string and number, adds the cost to the specified shopping product.
sumTotal() accepts no arguments, calculates the total of all know shopping product prices, takes into account the amount .
write - prints the information about the shopping products, in the same format from the example below.
cart .buyProduct({ item: 'jameson', quantity: '1'}) .buyProduct({ item: 'bud light', quantity: '3'}) .buyProduct({ item: 'corona', quantity: '4'}) .buyProduct({ item: 'beer', quantity: '1'}) .sumPrice('tequila', 5.99) .deleteProduct('corona') .sumPrice('beer', 5.04) .sumTotal() .write
//expected output : // Item: jameson | Quantity: 1 | Price: n/a // Item: bud light | Quantity: 3 | Price: n/a // Item: corona | Quantity: 3 | Price: $5.99 // Item: beer | Quantity: 1 | Price: $1.04 // Total: $19.01
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
