-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathassignment2.js
265 lines (235 loc) · 6.02 KB
/
assignment2.js
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//create five if statements
// create five switch cases
//create a switch case for arrAYS
//1. SWITCH CASE
// Example One (water sports)
let watersports = "Raft";
switch (watersports) {
case "Surfing":
console.log("This is riding a wave")
break;
case "Swimming":
console.log("This is moving under water using one's body.")
break;
case "Fishing":
console.log("This is pulling fish from the water body")
break;
case "Rafting":
console.log("This is riding a wave on a raft.")
break;
default:
console.log("Please pick a water Sport")
break;
}
//Example Two (snacks)
let snacks = "Gorillos";
switch (snacks) {
case "kernels":
console.log("Hard")
break;
case "crisps":
console.log("could either be cassava or potato ")
break;
case "Gorillos":
console.log("they are a bit puffy")
break;
default:
console.log("sweet Corn is the way to go")
break;
}
//Example 3 (teachers)
let badTeacher = "ben"
switch(badTeacher){
case "ben":
console.log("Ben is a bad teacher")
break;
case "trudy":
console.log("the teacher with lugambo!")
break;
case "Paul":
console.log("the computer guy")
break;
case "Solomon":
console.log("The chemistry Messiah")
break;
default:
console.log("She/he is a member of staff.")
break;
}
//example four (drugs)
let analgesics = "Morphine"
switch (analgesics) {
case "codeine":
console.log("Painkiller")
break;
case "fentanyl":
console.log("kills pain")
break;
case "Methadone":
console.log("its mildly sedative.")
break;
default:
console.log("Only analgesics available.")
break;
}
//example five novels
let authors = "Ana Huang"
switch (authors) {
case "J.K Rowling":
console.log("The Harry Potter Series")
break;
case "Dan Brown":
console.log("The Robert Langdon Stories")
break;
case "Danielle Steele":
console.log("Fictional romance is her specialty.")
break;
case "Veronica Roth":
console.log("The divergent series")
break;
case "Sarah. J. Maas":
console.log("The court of glass series")
break;
default:
console.log("Ana Huang is lit")
break;
}
//SWTCH CASES FOR ARRAYS
//TRIAL ONE
let fruits = ["Apple", "Banana", "Orange"];
for (let i = 0; i < fruits.length; i++) {
switch (fruits[i]) {
case "Peach":
console.log("These may be extinct in Uganda.");
break;
case "Dragon fruit":
console.log("Typically underrated gift of mother nature");
break;
case "Strawberry":
console.log("A red polka dotted berry that doesnt taste the way it looks.");
break;
default:
console.log("No available description.");
}
}
//TRIAL TWO
var myArray = ["peas", "soya", "nuts", "raisins"];
for (var i = 0; i < myArray.length; i++) {
switch (myArray[i]) {
case "peas":
console.log("Found peas!");
break;
case "soya":
console.log("Found soya!");
break;
case "nuts":
console.log("Found nuts!");
break;
case "raisins":
console.log("Found raisins!");
break;
default:
console.log("Unknown item found");
break;
}
}
//TRIAL THREE
var myArray = ["pants", "dress", "skirt", "shirt", "short"];
for (var i = 0; i < myArray.length; i++) {
switch (myArray[i]) {
case "pants":
console.log("He wore pants.");
break;
case "dress":
console.log("She wore a dress.");
break;
case "skirt":
console.log("She wore a skirt.");
break;
case "shirt":
console.log("She owns a shirt.");
break;
case "short":
console.log("She picked a short");
break;
default:
console.log("Unknown item found");
}
}
//TRIAL FOUR
var cars = ["bentley", "mercedes", "escalade", "jaguar", "g-wargon"];
for (var i = 0; i < cars.length; i++) {
switch (cars[i]) {
case "bently":
console.log("A Bentley");
break;
case "mercedes":
console.log("A Mercedes");
break;
case "escalade":
console.log("An Escalade");
break;
case "jaguar":
console.log("A Jaguar");
break;
case "g-wargon":
console.log("The G-Wargon");
break;
default:
console.log("Unknown item found");
}
}
//TRIAL FIVE(with concatination)
var continents = ["Africa", "Asia", "Europe", "Antarctica"];
var cases = ["Uganda", "China", "USA", "Northpole"];
for (var i = 0; i < cases.length; i++) {
switch (cases[i]) {
case "Uganda":
console.log("Uganda is located in " + continents[0]);
break;
case "China":
console.log("China is located in " + continents[1]);
break;
case "USA":
console.log("USA is located in " + continents[2]);
break;
case "Northpole":
console.log("The North Pole is located in " + continents[3]);
break;
default:
console.log("Learn how to utilize your Atlas");
}
}
//IF STATEMENTS
//TRIAL ONE
var temperature = 25;
if (temperature > 30) {
console.log("It's hot outside!");
} else if (temperature > 20) {
console.log("It's warm outside!");
} else {
console.log("It's cool outside!");
}
//TRIAL TWO
var dehydration = "severe";
if (dehydration = "mild") {
console.log("You are experiencing mild dehydration. Remember to drink water.");
} else if (dehydration = "severe") {
console.log("You are experiencing severe dehydration. Seek medical attention immediately.");
} else {
console.log("Unknown dehydration level. Please consult a healthcare professional.");
}
//TRIAL FOUR
var gender = "male";
if (gender == "female") {
console.log("Welcome, Madam!");
} else {
console.log("Welcome, Sir!");
}
//TRIAL FIVE
var bible = "oldTestament";
if (bible = "newTestament") {
console.log("This is the New Testament.");
} else {
console.log("Invalid input.");
}