This repository was archived by the owner on Nov 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek2-javascript.js
More file actions
215 lines (133 loc) · 3.04 KB
/
week2-javascript.js
File metadata and controls
215 lines (133 loc) · 3.04 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
// 1
function sum(a, b, c){
return a + b + c;
}
console.log(sum(1, 2, 3));
// 2
function colorCar(color){
return "a " + color + " car.";
}
console.log(colorCar("red"));
// 3
let obj = {
"firstKey": "firstValue",
"secondKey": "secondValue",
"thirdKey": "thirdValue",
"forthKey": "forthValue"
};
function objPrinter(x){
return x;
}
console.log(objPrinter(obj));
// 4
function vehicleType(color, code){
let vehicle = {
1: "car",
2: "motorbike"
};
return "a " + color + " " + vehicle[code];
}
console.log(vehicleType("blue", 2));
// 5
console.log(3 == 3 || false);
// 6
function vehicleType(color, code, age){
let vehicle = {
1: "car",
2: "motorbike",
3: "new",
4: "refurbished",
5: "used"
};
return "a " + color + " " + vehicle[age] + " " + vehicle[code];
}
console.log(vehicleType("green", 2, 4));
// 7&8
let vehicles = [
"car",
"motorbike",
"bike",
"caravan",
"airplane"
]
console.log(vehicles[2]);
// 9
function vehicleType(color, age, code){
let vehicleAge = {
1: "used",
2: "refurbished",
3: "new"
};
let vehicles = {
1: "caravan",
2: "motorbike",
3: "bike",
4: "car",
5: "airplane"
};
return "a " + color + " " + vehicleAge[age] + " " + vehicles[code];
}
console.log(vehicleType("green", 3, 1));
// 10&11
let vehicles = [
"car",
"motorbike",
"bike",
"caravan",
"airplane"
];
let s = "";
let x = vehicles.length - 1;
for (i = 0; i < x; i++){
s += vehicles[i] + ", ";
}
console.log("Amazing Joe's Garage, we service " + s + vehicles[x] + ".");
// 12
let emptyObj = {};
console.log(emptyObj)
// 13
/* Didn't work out and I don't want to write stuff I didn't understand haha */
// 14
function container(a){
return a;
}
function content(a, b, c){
let sum = a + b + c;
return (sum);
}
console.log(container(content(2, 4, 5)));
// 15
let x = [1,2,3];
let y = [1,2,3];
let z = y;
console.log("This (x == y) is " + (x==y));
console.log("This (x === y) is " + (x===y));
console.log("This (z == y) is " + (z==y));
console.log("This (z == x) is " + (z==x));
// 16
let o1 = { foo: "bar"};
let o2 = { foo: "bar"};
let o3 = o2;
console.log(o2 === o3);
o2 = { foo1: "bar1"};
console.log(o2 === o3);
console.log(o3);
//o2 does not change o3 because o3 is assigned to its old value not o2 itself
console.log(o1==o3);
o1 = { foo2: "bar3"};
console.log(o1);
console.log(o1==o3);
console.log(o3);
//o1 doesn't change o3 becuase there is no relationship between them at all
/* It does matter because if you assigned o3 to o2 (let o3 = o2;)
That creats a new variable and gives it the same value as o2.
But if you assigned o2 to o3 ( let o2 = o3;) you will get an error because you've already declared o2 and you cannot declare a variable twice, only change it and to do that you don't need to use (let).
Even if you just assigned o2 to o3 (o2 = o3) It will still give an error because o3 has not been defined yet
*/
// 17
/*It returns a string, because typeOf (anything) is always given in a string.
Proof?
*/
let bar = 42;
typeof typeof bar;
//done