Question: Open tc_cart.js . In your script, you will calculate a running total of the cost of the order. Declare a variable named orderTotal and set
Open tc_cart.js. In your script, you will calculate a running total of the cost of the order. Declare a variable named orderTotal and set its initial value to 0.
Declare a variable named cartHTML that will contain the HTML code for the contents of the shopping cart, which will be displayed as a table. Set its initial value to the text string:
| Item | Description | Price | Qty | Total |
For Loop
Create a for loop that loops through the entries in the item array. Each time through the loop, execute the commands described in the following steps:
Add the following HTML code to the value of the cartHTML variable
| where item is the current value from the item array.
Add the following HTML code to the cartHTML variable to display the description, price, and quantity ordered of the item
| description | $ price | quantity |
where description is the current value from the itemDescription array, price is the current value from the itemPrice array preceded by the $, and quantity is the current value from the itemQty array.
Declare a variable named itemCost equal to the price value multiplied by the quantity value for the current item.
Add the following HTML code to the cartHTML variable to display the cost for the item(s) ordered, completing the table row
| $ cost |
where cost is the value of the itemCost variable, preceded by a $.
Add the value of the itemCost variable to the orderTotal variable to keep a running total of the total cost of the customer order.
For Loop Completion
After the for loop has completed, add the following HTML code to the value of the cartHTML variable, completing the shopping cart table
| Subtotal | $ total |
where total is the value of the orderTotal variable, preceded by a $.