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:

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

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

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

ItemDescriptionPriceQtyTotal
description $ price quantity $ cost
Subtotal $ total

where total is the value of the orderTotal variable, preceded by a $.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!