-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcook.html
More file actions
292 lines (268 loc) · 7.45 KB
/
Copy pathcook.html
File metadata and controls
292 lines (268 loc) · 7.45 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
function var1() {
firstvar = 1;
var output = "";
/* output = "firstvar is " + firstvar + "\n";
console.log(output);*/
if (typeof firstvar === "undefined") {
output = "firstvar is undefined\n";
} else {
output = "firstvar is defined\n";
}
if (typeof secondvar === "undefined") {
output += "secondvar is undefined\n";
} else {
output += "secondvar is defined\n";
}
console.log(output);
}
var1();
console.log(firstvar);
//NEW
var outerWear = "Sweater";
function ourFit() {
var outerWear = "Gown";
console.log("This is what we are wearing: " + outerWear);
return outerWear;
}
console.log(ourFit());
console.log(outerWear);
ourFit();
</script>
<script>
function newe(arr, item) {
arr.push(item);
return arr.shift();
}
testArray = [1, 2, 3, 4, 5, 6];
console.log("Before:" + JSON.stringify(testArray));
console.log(newe(testArray, 7));
console.log("After:" + JSON.stringify(testArray));
//NEW
function boolcheck(val) {
if (val === "14") {
return "Equal";
}
return "Not Equal";
}
console.log(boolcheck(14));
</script>
<script>
var names = [
"Hole-in-one!",
"Eagle",
"Birdie",
"Par",
"Bogey",
"Double Bogey",
"Go home",
];
function golf(par, strokes) {
if (par == strokes) {
return names[3];
} else if (par - 1 == strokes) {
return names[2];
} else if (strokes <= par - 2) {
return names[1];
} else if (strokes == 1) {
return names[0];
} else if (strokes == par + 1) {
return names[4];
} else if (strokes == par + 2) {
return names[5];
} else if (strokes >= par + 3) {
return names[6];
}
}
console.log(golf(11, 9));
//NEW
function abtest(a, b) {
if (a < 0 || b < 0) {
return undefined;
}
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
console.log(abtest(62, 2));
//NEW
function phoneticLookUp(val) {
var result = "";
var lookup = {
alpha: "Adams",
bravo: "Boston",
charlie: "Chicago",
delta: "Denver",
echo: "Easy",
foxtrot: "Frank",
};
result = lookup[val];
return result;
}
console.log(phoneticLookUp("charlie"));
//NEW
var myObj = {
gift: "Pony",
pet: "kitten",
bed: "sleigh",
};
function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} else {
return "Not found";
}
}
console.log(checkObj("gift"));
//NEW
var myPlants = [
{
tree: "fig",
list: ["Trunk", "Leaf", "Stem"],
},
{
tree: "Mango",
list: ["Stem", "Fruit", "Branch"],
},
];
console.log(myPlants[0].tree);
console.log(myPlants[1].list[2]);
console.log(myPlants[0]["tree"]);
</script>
<script>
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name",
"Livin' on a Prayer",
"Wanted Dead or Alive",
],
},
2468: {
album: "1999",
artist: "Prince",
tracks: ["1999", "Little Red Corvette"],
},
1245: {
artist: "Robert Palmer",
tracks: [],
},
5439: {
album: "ABBA Gold",
},
};
var collectionCopy = JSON.parse(JSON.stringify(collection));
//collectionCopy is for the purposed of testing the function updateRecords
function updateRecords(id, prop, value) {
if (value === "") //deletes the property if value is empty string
{
delete collection[id][prop];
} else if (
/* else if (id === "") //deletes the property if value is empty string
{
JSON.stringify(id);
delete collection[prop][value];
} */
prop === "tracks"
) //if prop is tracks but value isn't empty string, push the value to the end of the tracks array
{
collection[id][prop] = collection[id][prop] || [];
collection[id][prop].push(value);
} else //for all other cases, update or set the value for the property
{
collection[id][prop] = value;
}
return collection;
}
updateRecords(1245, "artist", "Marlette");
console.log(updateRecords(5439, "artist", "Roxette"));
// console.log(updateRecords(5439, "tracks", "Take a Chance on Me"));
// console.log(updateRecords(2548, "artist", ""));
/*console.log(updateRecords("", "artist", "Prince"));*/
//NEW
var myArray = [];
for (var i = 1; i > -66; i--) {
myArray.push(i);
}
console.log(myArray);
//NEW
var ourArray = [2, 7.6, 4, 2];
var total = 0;
for (i = 0; i < ourArray.length; i++) {
total += ourArray[i];
}
console.log(total);
//NEW
function multiplyAll(arr) {
var product = 1;
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
return product;
}
var product = multiplyAll([
[1, 2],
[3, 4],
[5, 6, 7],
]);
console.log(product);
//NEW
var contacts = [
{
firstname: "Akira",
lastname: "Laine",
number: "0543236543",
likes: ["Pizza", "Coding", "Brownie Points"],
},
{
firstname: "Harry",
lastname: "Potter",
number: "0994372684",
likes: ["Hogwarts", "Magic", "Hagrid"],
},
{
firstname: "Sherlock",
lastname: "Holmes",
number: "0487345643",
likes: ["Intriguing Cases", "Violin"],
},
{
firstname: "Kristian",
lastname: "Whitney",
number: "0123456789",
likes: ["JavaScript", "Gaming", "Go"],
},
];
function property(name, prop) {
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstname == name) {
return contacts[i][prop] || "No such property";
}
}
return "No such contact";
}
// console.log(property("Kristian", "number")); OR
var data = property("Sherlock", "firstname");
console.log(data);
var data = property("Sherlock", "lastname");
console.log(data);
//Alternatively
/*function property(name, prop) {
const contact = contacts.find(c => c.firstname === name);
return contact?.[prop] ?? (contact ? "No such property" : "No such contact");
}*/ // nullish coalescing operator and optional chaining operator can be used to simplify the function.
</script>
</body>
</html>
// hello