-
Notifications
You must be signed in to change notification settings - Fork 0
/
DriveThruOrder.html
71 lines (64 loc) · 2.85 KB
/
DriveThruOrder.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<title>Drive Through</title>
<style>
.panel {
position: fixed; top: 20%; left: 40%;
border: blue solid 84px;
font-family: "Comic Sans MS", "Comic Sans", cursive;
}
</style>
<script>
var options = ["Hamburger", "Cheeseburger", "Tenderloin", "Shake", "Drink", "Fries"];
var prices = [3.50, 3.75, 5.00, 2.50, 1.00, 1.50];
var total = 0;
function setOptions() {
var optionsBox = document.getElementById("options");
var totalBox = document.createElement("div");
totalBox.setAttribute("id", "totalCost");
var span = document.createElement("span");
span.setAttribute("id", "idea")
document.getElementById("receipt").appendChild(document.createTextNode("Total: "));
document.getElementById("receipt").appendChild(span);
for (var i = 0; i < options.length; i++) {
var txtNode1 = document.createTextNode(options[i] + " $" + prices[i].toFixed(2));
var p = document.createElement("p");
p.appendChild(txtNode1);
optionsBox.appendChild(p);
}
document.getElementById("receipt").appendChild(totalBox);
}
function printReceipt() {
var order = document.getElementById("order");
var i = 0;
while (i <= options.length) {
if (order.value == options[i]) {
var txt = document.createTextNode(order.value + " $" + prices[i].toFixed(2));
var div = document.createElement("div");
document.getElementById("idea").remove();
total += prices[i];
totStr = document.createTextNode("$" + total.toFixed(2));
document.getElementById("idea").appendChild(totStr);
div.appendChild(txt);
document.getElementById("receipt").insertBefore(div, document.getElementById("idea"));
break;
}
i++;
}
document.getElementById("order").value = "";
}
</script>
</head>
<body onload="setOptions()">
<div id=panel class=panel>
<div id=options>
</div>
<div id=in>
<input id=order type=text placeholder="Tenderloin" style="font-family: 'Comic Sans MS', 'Comic Sans', cursive;"></input>
<button type="submit" id=submit onclick="printReceipt()" value="Submit">Submit</button>
</div>
<div id=receipt>
</div>
</div>
</body>
</html>