-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
268 lines (200 loc) · 4.57 KB
/
app.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
264
265
266
267
268
//HW 1
/* let x = 2 + '2';//x = 22
let x = 2 + 2 + '2';
//x = 42
let x = 2 + true;
//x = 3
let x = 2 + true + '2';
//x = 32
let x = true + '2';
//x = true2
let x = Number('2');
//x = 2
let x = Number('Hello');
//x = NaN
console.log(typeof(x)); //x = Number
let x = Boolean(1, 5, 10000, 'hello');
//x = true
let x = Boolean(0, '', null)
//x = false
let x = '';
if ((x !== undefined) || (x !== null) || (x !== 0)) {
} */
//HW 2
/* const color = 'red';
switch(color){
case 'red':
console.log('Color is red');
break;
case 'blue':
console.log('Color is blue');
break;
default:
console.log('Color is not red or blue');
break;
}
switch(new Date(). getDay()){
case 0:
day = 'Sunday';
break;
case 1:
day = 'Monday';
break;
case 2:
day = 'Tuesday';
break;
case 3:
day = 'Wednesday';
break;
case 4:
day = 'Thursday';
break;
case 5:
day = 'Friday';
break;
case 6:
day = 'Saturday';
break;
}
console.log(`Today is ${day}`); */
//HW 3
/*
function greet(firstName = 'joe', lastName = 'mama'){
if(typeof firstName === 'undefined'){firstName = 'joe'}
if(typeof lastName === 'undefined'){lastName = 'mama'}
console.log('hey');
return 'hey' + firstName + ' ' + lastName;
}
greet();
console.log(greet());
const square = function(x = 3){
return x*x;
};
console.log(square());
(function(name){
console.log('hey' + name)
})('chad');
const todo = {
add: function(){
console.log('add todo');
},
edit: function(id){
console.log(`Edit todo ${id}`);
}
}
todo.delete = function(){
console.log('delete todo');
}
todo.add();
todo.edit(22);
todo.delete(); */
//HW 4
// var a = 1;
// let b = 2;
// const c = 3;
// function test(){
// var a = 4;
// let b = 5;
// const c = 6;
// console.log('Function scope: ', a, b, c);
// }
// test();
// if(true) {
// //block scope
// var a = 4;
// let b = 5;
// const c = 6;
// console.log('If scope:', a, b, c);
// }
// for(let a = 0; a < 10; a++) {
// console.log(`Loop: ${a}`);
// }
// console.log('Global scope: ', a, b, c);
//HW 5
//empty parentheses
// () => 42;
//single parameter, () optional
// (x) => 42;
// x => 42;
//multiple parameter, () required
/* (x, y) => 42; */
//statements
//function expression produces a value, function statement performs an action
//with arrow functions, you need curly braces and return
// var feedTheCat = (cat) => {
// if(cat === 'hungry') {
// return 'Feed the cat';
// } else {
// return 'Do not feed the cat.';
// }
// }
//if a function is in a block, must use return statement
// var addValues (x, y) => {
// return x + y;
// }
//object literal need wrapping parentheses
// x => ({y:x});
//HW 6
// const num1 = 100;
// const num2 = 50;
// let val;
//simple math with numbers
// val = num1 + num2;
// val = num1 - num2;
// val = num1 * num2;
// val = num1 / num2;
// val = num1 % num2;
//math object
// val = Math.PI;
// val = Math.E;
// val = Math.round(2.4);
// val = Math.ceil(2.4);
// val = Math.floor(2.8);
// val = Math.sqrt(64);
// val = Math.abs(-3);
// val = Math.pow(8, 2);
// val = Math.min(2, 33, 4, 1, 55, 6, 3, -2);
// val = Math.max(2, 33, 4, 1, 5, 55, 6, 3, -2);
// val = Math.random();
// val = Math.floor(Math.random() * 20 + 1);
// console.log(val);
// HW 8
// const alphabet = ['A', 'B', 'C', 'D', 'E', 'F'];
// const numbers = ['1', '2', '3', '4', '5', '6'];
/* const a = alphabet[0];
const b = alphabet[1]; */
// const[a,, c, ...rest] = alphabet
// const newArray = [...alphabet, ...numbers]
// console.log(a);
// console.log(c);
// console.log(rest);
// console.log(newArray)
// function sumAndMultiply(a, b){
// return[a+b, a*b, /* a/b */]
// }
// const array = sumAndMultiply(4, 5)
// console.log(array)
// const [sum, multiply, division = 'No division'] = sumAndMultiply(4,5);
// console.log(sum);
// console.log(multiply);
// console.log(division);
const personOne = {
name: 'Kyle',
age: 24,
favoriteFood: 'rice',
address: {
city: 'somewhere',
state: 'one of them'
}
}
// const personTwo = {
// age: 32,
// favoriteFood: 'watermelon',
// }
// const personThree = {...personOne, ...personTwo}
// // const {name: firstName, address: {city}} = personTwo;
// console.log(personThree)
function printUser({name, age, favoriteFood = 'watermelon'}) {
console.log(`Name is: ${name}. Age is ${age}. Favorite food is ${favoriteFood}`)
}
printUser(personOne)