-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
202 lines (172 loc) · 4.67 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<html>
<h1>Hot Drinks Machine!!!</h1>
<script>
//units
var tea = 3;
var heating = 7;
var lemon = 1;
var water = 4;
var coffee = 5;
var chocolate = 4;
var cups = 5;
var milk = 4;
var sugar = 5;
var coffeeWaste = 0;
var unitsHaveBeenSet = false
function setTheUnits() {
if (unitsHaveBeenSet == false) {
tea = 3;
heating = 7;
lemon = 1;
water = 4;
chocolate = 4;
coffee = 5;
cups = 5;
milk = 4;
sugar = 5;
coffeeWaste = 0;
console.log("units have been set");
unitsHaveBeenSet = true;
}
}
setTheUnits();
function makeDrink(drink) {
console.log("makeDrink");
if (drink == "tea")
makeLemonTea();
if (drink == "coffee")
makeCoffee();
if (drink == "chocolate")
makeHotChocolate();
}
function makeLemonTea() {
console.log("makeLemonTea");
if (water > 0) {
if (heating > 0) {
water = water - 1;
heating = heating - 1;
alert("Boiling some water! There is " + water + " units of water left");
} else {
alert("Error 2: Oh no! There's no hot left to boiling the water :-O");
return;
}
} else {
alert("Error 25: No water left");
return;
}
if (tea > 0) {
tea = tea - 1;
alert("Steeping the water in the tea!");
} else {
alert("Error 15: No more tea :-(");
return;
}
if (cups > 0) {
cups = cups - 1;
alert("Pouring tea in the cup!");
} else {
alert("Error 3: ran out of cups!");
return;
}
if (lemon > 0) {
lemon = lemon - 1;
alert("Adding the lemon!");
} else {
alert("Error 4: Ran out of lemon");
alert("Voila! Your non-lemon tea is served");
return;
}
alert("Voila! Your lemon tea is served :-)");
};
function makeCoffee() {
console.log("makeCoffee");
if (water > 0) {
if (heating > 0) {
water = water - 1;
heating = heating - 1;
alert("Boiling some water! There is " + water + " units of water left");
} else {
alert("Error 2: Oh no! There's no hot left to boiling the water :-O");
return;
}
} else {
alert("Error 8: No water left to make coffee");
return;
}
if (coffee > 0) {
if (coffeeWaste == 10) {
alert("Error 14: oh no! the coffee wasteage tray is full. No coffee for you today.");
return;
} else {
coffee = coffee - 1;
coffeeWaste = coffeeWaste + 1;
alert("Brewing the coffee grounds! Coffee wasteage has increased to " + coffeeWaste + " units");
if (cups > 0) {
cups = cups - 1;
alert("Pouring coffee in the cup!");
} else {
alert("Error 4: No cups left to hold your coffee. Mind your feet!");
return;
}
}
}
if (sugar > 0) {
if (milk > 0) {
sugar = sugar - 1;
milk = milk - 1;
alert("Adding the sugar and milk! There are " + milk + " units of milk left");
} else {
sugar = sugar - 1;
alert("Error 17: no milk left");
alert("Voila! Your coffee without milk is served :-)");
}
}
alert("Voila! Your coffee is served :-)");
};
function makeHotChocolate() {
if (water > 0) {
if (heating > 0) {
water = water - 1;
heating = heating - 1;
alert("Boiling some water! There is " + water + " units of water left and " + heating + " heating left");
} else {
alert("Error 2: Oh no! There's no hot left to boiling the water :-O");
return;
}
} else {
alert("Error 7: No water left to make hot chocolate");
return;
}
if (chocolate > 0) {
chocolate = chocolate - 1;
alert("Adding drinking chocolate powder to the water!! There are " + chocolate + " units of chocolate left in the machine");
} else {
alert("Error 11: no chocolate left");
return;
}
if (cups > 0) {
cups = cups - 1;
alert("Pouring chocolate in the cup! There are " + cups + " left in the machine");
} else {
alert("Error 9: no cup to put the hot chocolate in");
return;
}
alert("Voila! Your hot chocolate is served :-)");
};
</script>
<div>
Click on a link to make the drink!!!
</div>
<div>NOTE: this web application requires JavaScript to run</div>
<div style="background-color:blue">
<a id="tea" style="color:white" href="#" onclick="makeLemonTea();">Make Lemon Tea!</a>
</div>
<div style="background-color:red">
<a id="coffee" style="color:yellow" href="#" onclick="makeCoffee();">Make Coffee!</a>
</div>
<div style="background-color:brown">
<a id="chocolate" style="color:green" href="#" onclick="makeHotChocolate();">Hot Chocolate!</a>
</div>
<p>Hot Drinks Machine Copyright Alan 1998</p>
<p>This site works best with Internet Explorer 4</p>
</html>