Hello I am trying to display the total cost after the user enters a product ID, controlled by a switch statement. However the total variable ends up being the product ID, not the price. I want the total to be the sums of the prices.
<script type ="text/javascript">
// Switch statement & variables with their proper values, declare the product and total too
var product;
var price;
var total = 0;
switch(product)
{
case 1:
price = 2.98;
break;
case 2:
price = 4.50;
break;
case 3:
price = 9.98;
break;
case 4:
price = 4.49;
break;
case 5:
price = 6.87;
break;
default:
price = undefined;
}
document.write("Welcome, please enter a product number. Press '0' to terminate the buying sequence.");
document.write("<br />");
document.write("Enter the number (1 - 5) of the product you would like.");
document.write("<br />");
// Until the user enters "end" keep asking what product they want
while(product != 0)
{
product = prompt("Please enter which product you would like: ");
total = total + price;
}
document.write("The total cost is: $" + total);
</script>
<h3>P.333 10.13</h3>
<script type ="text/javascript">
</script>