Concept explainers
a.
To addingcalcItemCost() to foodItem prototype, this method returns the priceproperty multiplied by the qty propertyin file rb_build.js.
b.
To add calcCartTotal()to the cart prototype, this method, calculates the cartTotal, by using a loop through the items array, applyingthe calcItemCost() method to each item in the array and storing the sum of the item costs in thetotalCost property in file rb_build.js.
c.
To add addToCart() to the foodItem prototype,this method has a single parameter named cart
andby using the push() array method to add the foodItem object to the items array of the cart.in file rb_build.js.
d)
To add removeFromCart() to the foodItem prototype, this method has a single parameter named cart, loop through the items array in the cart object and for each item test whether it is equal to the foodItem object. If it is, use the splice() method to remove the object from the items array and break off the for loop in file rb_build.js.
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
NEW PERSP.ON COMP.CONCEPTS-PACKAGE
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning