-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript-intro-notes.html
More file actions
264 lines (215 loc) · 6.47 KB
/
javascript-intro-notes.html
File metadata and controls
264 lines (215 loc) · 6.47 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
// var a = 1;
// // 3
// var b = a++;
// // 1
// var c = ++a;
// // 3
// // what is the value of a, b, and c?
//
// var d = "hello";
// var e = false;
//
// d++;
// // NaN
// e++;
// // 1
//
// var perplexed; // perplexed is undefined (no value is assigned)
// // undefined
// perplexed + 2;
// // NaN
//
// var price = 2.7;
// price.toFixed(2);
// // "2.70"
//
// var price = "2.7";
// price.toFixed(2);
// // is not a function
//
//
// isNaN(0)
// // false
//
// isNaN(1)
// // false
//
// isNaN("")
// // false
//technically 0
// isNaN("string")
// // true
//
// isNaN("0")
// // false
//
// isNaN("1")
// // false
//
// isNaN("3.145")
// // false
//
// isNaN(Number.MAX_VALUE)
// // false
//
// isNaN(Infinity)
// // false
//
// isNaN("true")
// // true
//
// isNaN(true)
// false
// isNaN("false")
// // true
//
// isNaN(false)
// // false
//
// // to illustrate why the isNaN() function is needed:
// NaN == NaN
// // false
//
// !true
// // false
//
// !false
// true
// !!true
// // true
// !!false
// // false
// !!0
// // false
// !!-0
// // false
// !!1
// // true
// !!-1
// // true
// !!0.1
// // true
// !!"hello"
// // true
// !!""
// // false
// !!''
// // false
//
// !!"false"
// // true
//
// !!"0"
// true
// var sample = "Hello Codeup";
// Use .length to find the number of characters in the string.
// sample.length; 12
// Try to make the sample string all upper or all lower case.
// sample.toLowerCase();
// sample.toUpperCase();
// Update the variable sample via concatenation so that it contains "Hello Codeup Students".
// sample += " Students";
// Replace "Students" with "Class".
// sample.replace("Students", "Class");
//sample = sample.replace("Students", "Class");
// Find the index of "c" using .indexOf(). What do you observe?
// -1 (does not exist)
// Find the index of "C" using .indexOf().
// 6, start is 0
// Retrieve a substring that contains only the word "Codeup" by using indexOf() and substring().
// sample.substring(6, 12);
// sample.substring(sample.indexOf("C"), sample.indexOf("p") + 1);
// Write some JavaScript code, that is, variables and operators, to describe the following scenarios. Do not worry about the real operations to get the values, the goal of these exercises is to understand how real world conditions can be represented with code.
// You have rented some movies for your kids: The little mermaid (for 3 days),
// Brother Bear (for 5 days, they love it),
// and Hercules (1 day, you don't know yet if they're going to like it).
// If price for a movie per day is $3, how much will you have to pay?
// var littleMermaid = 3;
// var brotherBear = 5;
// var hercules = 1;
// (littleMermaid + brotherBear + hercules) *3;
var littleMermaid = 3 * 3;
var brotherBear = 5 * 3;
var hercules = 1 * 3;
function priceForMovies(x, y, z){
return littleMermaid + brotherBear + hercules;
}
console.log(priceForMovies(littleMermaid, brotherBear, hercules));
// var days = ["littleMermaid" + "brotherBear" + "hercules"];
// Suppose you're working as a contractor for 3 companies: Google, Amazon and Facebook,
// they pay you a different rate per hour.
// Google pays $400,
// Amazon $380,
// and Facebook $350.
// How much will you receive in payment for this week?
var googleRate = 400;
var amazonRate = 380;
var facebookRate = 350;
googleMoney = 400 * 6;
amazonMoney = 380 * 4;
facebookMoney = 350 * 10;
var paycheck = googleMoney + amazonMoney + facebookMoney;
console.log(paycheck);
var amazon = 380 * 4;
var google = 400 * 6;
var facebook = 350 * 10;
function myPayCheck(x, y, z){
return (amazon) + (google) + (facebook);
}
console.log(myPayCheck(amazon, google, facebook));
// You worked 10 hours for Facebook, 6 hours for Google and 4 hours for Amazon.
// A student can be enrolled in a class only if the class is not full and the class
// schedule does not conflict with her current schedule.
// var clasNotFull = true;
// var classConflict = true;
// var enrolled = classNotFull && classConflict;
// var classAt8am = false;
// var classSize = 125;
// var currentClassSize = 108;
// var canRegister = (currentClassSize < classSize) && !classAt8am;
// A product offer can be applied only if a person buys more than 2 items,
// and the offer has not expired. Premium members do not need to buy a specific
// amount of products.
// var hasPremium = true;
// var cartSize = 6;
// var offerValid = true;
//
// var canHaveDiscount = offerValid && (cartSize > 2 || hasPremium);
// premiumMember = true;
// offerValid = true;
// moreThanTwo => 2 && offerValid == true;
// Use the following code to follow the instructions below:
// var username = 'codeup';
// var password = 'notastrongpassword';
// Create a variable that holds a boolean value for each of the following conditions:
// the password must be at least 5 characters
// var atLeastFivePassword = password.length >= 5;
// var password.length >= 5;
// the password must not include the username
// var usernameNotInPassword = password.indexOf(username) === -1;
// var usernameNotInPassword = ! password.includes(username;
// the username must be no more than 20 characters
// var userNameNotaParagraph = username.length <= 20;
// var username.length <= 20;
// neither the username or password can start or end with whitespace
// var whitespace = username.trim() && password.trim();
// var noWhitespace = username.trim() === username && password.trim() === password;
// username.trim();
// password.trim();
// console.log(password);
// console.log(username);
// console.log(password.length);
</script>
</body>
</html>