-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathexercises.js
314 lines (253 loc) · 8.77 KB
/
exercises.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
If statements - Evaluates (or checks) a condition. If the condition is true, any statements in the subsequent code block are executed
*/
if(today === "Friday"){
return "Let's Party!";
};
/*
If/else statements = Evaluates (or checks) a condition. If the condition is true, the first code block is executed. If the condition is false, the second code block is executed instead.
*/
if(today === "Friday"){
return "Let's Party!";
}else{
return "Get back to coding!";
};
/*
* #1
* Function - canVote
* Create a function named `canVote` which will take a parameter: `age`.
*
* @param Datatype: Number `age`
* @return Datatype: Boolean
*
* The function will return true if the number passed into the function is equal to or greater than Hawaii's voting age. Console.log your result.
*/
/*
* #2
* Function - login
* Create a function named `login` which will take a parameter: `password`.
*
* @param Datatype: String `password`
* @return Datatype: String
*
* The function will return the message: "Login Success!", if the string passed into the function is "test1234"
* Console.log your result.
*/
/*
* #3
* Function - isGreaterThan
* Create a function named `isGreaterThan` which will take two parameters: `first` and `second`
*
* @param Datatype: Number `first`
* @param Datatype: Number `second`
* @return Datatype: Boolean
*
* The function will return true if the first number is greater than the second.
* Console.log your result.
*/
/*
* #4
* Function - mustBeTrue
* Create a function named `mustBeTrue` which will take a parameter: `boo`.
*
* @param Datatype: Boolean `boo`
* @return Datatype: Boolean
*
* The function will return true if the value passed into the function is "true".
* Console.log your result.
*/
/*
* #5
* Function - bigBird
* Create a function named `bigBird` which will take a parameter: `word`.
*
* @param Datatype: String `word`
* @return Datatype: String
*
* The function will return the message "Word to Big Bird!", if the string passed into the function is a three letter word.
* Console.log your result.
*/
/*
* #6
* Function - isEqual
* Create a function named `isEqual` which takes two parameters: `first` and `second`.
*
* @param Datatype: String `first`
* @param Datatype: String `second`
* @return Datatype: String
*
* The function will return the message "You look mahvelous!", if the strings are equal, otherwise return the message: "I don't know who you are anymore."
* Console.log your result.
*/
/*
* #7
* Function - notEqual
* Create a function named `notEqual` which takes two parameters: `first` and `second`.
*
* @param Datatype: String `first`
* @param Datatype: String `second`
* @return Datatype: String
*
* The function will return the message "Opposites do attract", if the strings are not equal, otherwise return the message: "Cause it's like you're my mirror."
* Console.log your result.
*/
/*
* #8
* Function - spareChange
* Create a function named `spareChange` which takes a parameter: `money`.
*
* @param Datatype: Number `money`
* @return Datatype: Boolean
*
* The function will return true if the number passed into the function is greater than 100, otherswise it will return false.
* Console.log your result.
*/
/*
* #9
* Function - dirty30
* Create a function named `dirty30` which takes three parameters: `one`, `two` and `three`.
*
* @param Datatype: Number `one`
* @param Datatype: Number `two`
* @param Datatype: Number `three`
* @return Datatype: Boolean
*
* The function will return true if the sum of all the number values is greater than 30, otherwise it will return false.
* Console.log your result.
*/
/*
* #10
* Function - evenStevens
* Create a function named `evenStevens` which takes a parameter: `num`.
*
* @param Datatype: Number `num`
* @return Datatype: Boolean
*
* The function will return true if the number passed in is an even value, otherwise it will return false.
* Console.log your result.
*/
/*
* #11
* Function - daClub
* Create a function named `daClub` which takes two parameters: `cover` and `age`.
*
* @param Datatype: Number `cover`
* @param Datatype: Number `age`
* @return Datatype: String
*
* The function will return the message: "Welcome to the Legends Lounge." if BOTH values are over 21, otherwise it will return the message: "Chuck E Cheese is across the street."
* Console.log your result.
*/
/*
* #12
* Function - graduation
* Create a function named `graduation` which takes two parameters: `credits` and `thesis`.
*
* @param Datatype: Number `credit`
* @param Datatype: Boolean `thesis`
* @return Datatype: String
*
* The function will return the message: "Congratulations on a job well done." if EITHER the number value is greater than or equal to 120 or boolean value is true, otherwise return the message: "See you in summer school."
* Console.log your result.
*/
/*
* #13
* Function - moneyTrain
* Create a function named `moneyTrain` which takes a parameter: `speed`.
*
* @param Datatype: Number `speed`
* @return Datatype: String
*
* The function will return the message: "You are riding Honolulu's Rail.", if the number value is less than 50, otherwise it will return the message: "You are riding an Amtrak.", if the number value is less than 100, and return the message: "Now you ballin' in the Shinkansen!", if the number value is greater than or equal to 100.
* Console.log your result.
*/
/*
* #14
* Function - buyDoughnut
* Create a function named `buyDoughnut` which takes NO parameter.
* Declare a variable named `budget` and assign it with a number value that is greater than 20.
* Declare a variable named `doughnutPrice` and assign it with a number value that is greater than 0 but less than 6.
* Declare a variable named `doughnutBought` and assign it with a number value of 0.
*
* When the function is invoked, the budget will be decreased by the doughnutPrice and doughnutBought will increase by 1.
* Console.log budget and doughnutBought.
* Invoke your function again.
* Console.log budget and doughnutBought again.
*/
/*
For loops - A for loop checks a condition a specific number of times and allows us to execute a code block and evaluate a condition to determine if our loop should run again.
The for loop is made up for 3 parts:
1) Initialization (i.e. var i = 0;)
2) Condition (i.e. i<arr.length;)
3) Update (i.e. i++)
*/
var toyotaModels = ["Corolla", "Prius", "4 Runner", "Camry", "Land Cruiser"];
for (var i = 0; i<toyotaModels.length; i++){
console.log("Toyota " + toyotaModels[i]);
}
/*
* #15
* Create a for loop that will iterate 5 times and console.log the following:
* "Player: 1"
* "Player: 2"
* "Player: 3"
* "Player: 4"
* "Player: 5"
*/
/*
* #16
* Create a for loop that will iterate and console.log each item in the array below:
*/
var myFavFoods = ["lemon bar", "carrot cake", "nachos", "bacon cheeseburger", "ramen", "sweet potato fries", "chimichanga"];
/*
* #17
* Function - sumItUp
* Create a function named sumItUp which takes a parameter: `arr`.
*
* @param Datatype: Array `arr`
* @return Datatype: Number
*
* Declare a variable named `numArray` and assign it with an array of 5 random numbers of your choice.
* Declare a variable named `total` and assign it with a number value of 0.
*
* The function will loop through and add up all the values in the array that is passed into the function and return the total.
* Console.log your result.
*/
/*
* #18
* Function - allStars
* Create a function named `allStars` which takes a parameter: `ballers`.
*
* @param Datatype: Array `ballers`
* @return Datatype: Array
*
* The function will loop through the players array and will put all the even numbered indexed players in the empty east array and the rest in the empty west array.
* Console.log both the east and west arrays.
*/
var players = ["LeBron", "Linsanity", "Kawhi", "Kobe", "Yao Ming", "Bird", "Jordan"];
var east = [];
var west = [];
/*
* #19
* Function - subways
* Create a function named `subways` which takes a parameter: `special`.
*
* @param Datatype: Array `special`
* @return Datatype: Array
*
* The function will loop through the array value and replace all the odd numbered indexed items with "Classic Tuna".
* Console.log your results.
*/
var subOftheDay = ["Teriyaki Chicken", "Spicy Italian", "Turkey", "BMT", "Black Forest Ham", "Meatball Marinara", "Veggie"];
/*
Final Boss
* #20
* Function - removeLetter
* Create a function named `removeLetter`, which takes a parameter `str`.
*
* @param Datatype: String `str`
* @return Datatype: Array
*
* The function will loop through the string value and put all the letters into an array, except for the letter "A" and "a". We don't want no stinking "A" or "a" in our array.
*/
var phrase = "An apple a day keeps Alice feeling awesome!"