/
main.js
223 lines (161 loc) · 3.42 KB
/
main.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
// Answer the following questions in this file using comments without running the code
// 1.
// What does `givenName` equal right now?
let givenName;
// A:udefined
// 2.
// What is `givenName` set to right now?
givenName = "Tim";
// A: Tim
// 3.
// What is `givenName` set to right now?
givenName = givenName;
// A: Tim
// 4.
// What is `greeting` set to?
let greeting = "Hello, how are you? " + givenName;
// A: Hello, how are you, Tim?
// 5.
// What is `math` set to?
let high = 50;
let low = 10;
let math = high - low;
// A:40
// 6.
// What is `math` set to?
math = high - "5";
// A:-5
// 7.
// Create a variable to calculate Tim's age
// The answer should read "Tim is 33 years old"
// The answer shoud not be written in a comment.
let born = 1984;
let today = 2017;
let age = today - born;
console.log('Tim is' + age + 'years old');
// 8.
// Adjust this code. Store some information in the following variables.
// A:
let yourName = "Charlie";
let instructorName = "Gavin";
// 9.
// Update the variables `yourName` and `instructorName` so the expression below reads correctly.
// A:
// This statement should read correctly
let statement = (yourName + " is taking a class at The Iron Yard, my instructor's name is " + instructorName);
// 10.
// We've created a variable named after each primitive type.
// Use the `=` operator to assign a value to each variable matching the type in the name.
let myNumber = 2;
let myString = "string";
let myBoolean = true;
// This one's a little tricky - think carefully about what makes a value "undefined"!
myUndefined =
// A:
// For questions 11 - 19: List which boolean value will be stored in each variable. (Remember: `==` does not check data type)
// 11.
x = (false == 0);
// A.true
// 12.
let y = (false == "");
// A.true
// 13.
let z = (0 == "");
// A.true
// 14.
let a = (null == null);
// A.true
// 15.
let b = (undefined == undefined);
// A. true
// 16.
let c = (undefined == null);
// A.true
// 17.
let d = (null == false);
// A.false
// 18.
let e = (NaN == null);
// A.false
// 19.
let f = (NaN == NaN);
// A.false
// 20.
// Fix the `if...else` statement below by adding an `if` keyword and conditional expression.
// Use the variable `thirsty` as part of your conditional expression.
// A:
let thirsty = true;
if (thirsty === true) {
console.log("I'm parched!");
} else {
console.log("I've had enough to drink.");
}
// For questions 21 - 29 list which statement will be logged.
// 21.
x;
if(x){
console.log("True!");
} else {
console.log("False!");
}
// A:False!
// 22.
if(""){
console.log("True!");
} else {
console.log("False!");
}
// A:True!
// 23.
// this expression will set x to NaN
x = 1 * undefined;
if(x){
console.log("True!");
} else {
console.log("False!");
}
// A:True!
// 24.
if(false){
console.log("True!");
} else {
console.log("False!");
}
// A:True!
// 25.
if(-5 && 5){
console.log("True!");
} else {
console.log("False!");
}
// A:False!
// 26.
if("Hello World!"){
console.log("True!");
} else {
console.log("False!");
}
// A:True!
// 27.
if({}){
console.log("True!");
} else {
console.log("False!");
}
// A:False!
// 28.
if({name: "Yehuda Katz"}){
console.log("True!");
} else {
console.log("False!");
}
// A:False!
// 29.
if(new Date()){
console.log("True!");
} else {
console.log("False!");
}
// A:False!
// 30.
// Link this file to the sibling `index.html` document, open the file in your browser and make sure there are no errors in your console.