In: Computer Science
A mail-order house sells five different products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write a script that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity
sold for one day Your program should use a switch statement to determine each product’s retail price and should calculate and output HTML5 that displays the total retail value of all the products sold last week. Use a prompt dialog to obtain the product number and quantity from the user. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.
HTML CODE PLZ
no need of database just need to use the given prices
ANSWER :
Code :-
<!DOCTYPE html>
<html lang="en">
<head> <!-- open of head -->
<meta charset="utf-8">
<title> Mail Order</title>
<link rel="shortcut icon" href="me.jpg">
</head>
<body> <!-- beginning of the body section -->
<header>
<h1>Mail Order </h1>
</header>
<script type="text/javascript">
function orderSummary() {
//hash for product costs
var productCost = {
//product1, $2.98; product 2, $4.50; product 3, $9.98; product 4,
$4.49; and product 5, $6.87.
1 : 2.98,
2 : 4.50,
3 : 9.98,
4 : 4.49,
5 : 6.87
}
var productSelected = [];
var quantity = [];
var count = getOrders(productSelected, quantity);
var i = 0;
var total = 0;
var diff = 0;
var text = "<table
cellspacing=\"3\"><tr><td>Product
ID</td><td>Quantity</td><td>Cost</td><td></tr>"
;
var cost = 0;
for(i = 0; i <count; i++) {
cost = quantity[i] * productCost[productSelected[i]];
total += cost;
text +=
"<tr><td>"+productSelected[i]+"</td><td>"+quantity[i]+"</td><td>$"+cost+
"</td><td></tr>";
}
text += "<tr><td>Total
Cost</td><td> </td><td>$"+total+"</td><td></tr></table>";
document.getElementById("content").innerHTML = text;
// alert(text);
}
function getOrders(productSelected, quantity) {
var i = 0;
var input = 0;
var loop = 1;
while(loop == 1) {
input = prompt("Enter Product Number: ");
if (input === null) {
loop =-1;
continue;
} else {
productSelected[i] = input;
input = prompt("Enter Quantity for Product#"+input+": ");
if (input === null) {
loop = 0;
continue;
}
quantity[i] = input;
i++;
}
}
return i;
}
</script>
<div id="content">
</div>
<script>
orderSummary();
</script>
</body>
</html>
Sample run :-
Hope it helps... please give an upvote. it's very important to me... thank you:?