-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
342 lines (309 loc) · 10.9 KB
/
Copy pathindex.js
File metadata and controls
342 lines (309 loc) · 10.9 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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// ⭐️ Example Challenge start ⭐️
/**
* ### Challenge `addNumbers`
*
* @instructions
* This function should be able to take two numbers as arguments
* and return the result of adding them together.
*
* For example, if we invoke `addNumbers` passing 5 and 3,
* the returned value should be 8.
*
* NOTE: This example has been completed for you.
*/
function addNumbers(num1, num2) {
return num1 + num2;
}
// ⭐️ Example Challenge end ⭐️
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
/**
* ### Challenge `sayGoodbye`
*
* @instructions
* This function should take an a name as an argument,
* and return a string that says 'Goodbye, {name}. Have a great day.'
*
* For example, if we invoke `sayGoodbye`
* passing 'Andy' as the argument,
* the returned value should look like: 'Goodbye, Andy. Have a great day.'
*
*/
function sayGoodbye(/* code here */) {
/* code here */
}
/**
* ### Challenge `temperatureCtoF`
*
* @instructions
* This function should take an a temperature in celsius as an argument,
* and return the temperature in fahrenheit, rounded to the nearest whole number.
*
* For example, if we invoke `temperatureCtoF`
* passing 24 as the argument,
* the returned value should be: 75
*
* Hint 1: The formula for converting celsius to fahrenheit is t*9/5 + 32 where t is the temperature in celsius.
* Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how.
*/
function temperatureCtoF(/* code here */) {
/* code here */
}
/**
* ### Challenge `temperatureInF`
*
* @instructions
* This function should take an a temperature and a unit (either 'F' or 'C') as arguments,
* and return the temperature in fahrenheit, rounded to the nearest whole number.
*
* For example, if we invoke `temperatureInF`
* passing 88, 'F' as the arguments,
* the returned value should be: '88F'
*
* If we invoke `temperatureInF`
* passing 24, 'C' as the arguments,
* the returned value should be: '75F'
*
* Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`.
*/
function temperatureInF(/* code here */) {
/* code here */
}
/**
* ### Challenge `makePersonObject`
*
* @instructions
* This function should take an id, a name and an email as arguments,
* and return an object with `id`, `name` and `email` properties.
*
* For example, if we invoke `makePersonObject`
* passing 5, 'Leia' and 'leia@leia.com' as arguments,
* the returned value should look like:
* {
* id: 5,
* name: "Leia",
* email: "leia@leia.com",
* }
*/
function makePersonObject(/* code here */) {
/* code here */
}
/**
* ### Challenge `getName`
*
* @instructions
* This function takes as its only argument
* an object containing a `name` property,
* and return a string that reads `Hello, my name is {name}`,
* where `{name}` is the name stored in the object.
*
* For example, if we invoke `getName`
* passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument,
* the returned value should look like `Hello, my name is Leia`.
*/
function getName(/* code here */) {
/* code here */
}
/**
* ### Challenge `appleIndex`
*
* @instructions
* This function takes as its only argument an array
* containing strings,
* and returns the index in the array of the string 'apple'.
*
* You may assume the string 'apple' will appear exactly
* once in the array.
*
* For example, if we invoke `appleIndex`
* passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument,
* the returned value should be: 2.
*/
function appleIndex(/* code here */) {
/* code here */
}
/**
* ### Challenge `isItAnApple`
*
* @instructions
* This function takes as its only argument an array
* containing strings,
* and returns an array of equal length containing the `true`
* if the corresponding entry in the original array is 'apple'
* and `false` if it is anything else.
*
*
* For example, if we invoke `isItAnApple`
* passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument,
* the returned value should be: [ false, true, false, false, true, false ].
*/
function isItAnApple(/* code here */) {
/* code here */
}
/*
// ⭐️ Example Test Data ⭐️
var inventory = [
{ id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 },
{ id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 },
{ id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 },
{ id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 },
{ id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 },
{ id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 },
{ id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 },
{ id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 },
{ id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 },
{ id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 },
{ id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 },
{ id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 },
{ id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 },
{ id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 }
/// ... Truncated
]
*/
/**
* ### Example Array Challenge:
*
* @instructions
* get3rdCar() should return the string `The is a Land Rover Defender Ice Edition`
*
*
* NOTE: This example has been completed for you.
**/
function get3rdCar(inventory) {
const the3rd = inventory[2];
return `The is a ${the3rd.car_make} ${the3rd.car_model}`
}
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
/**
* ### Challenge `getCarInfoByIndex`
*
* @instructions
* getCarInfoByIndex takes two arguments:
* (1) an array which is an inventory of cars like the preview above (see ⭐️ Preview Test Data ⭐️)
* (2) a number which is the desired index in the array.
* getCarInfoByIndex returns a string in the format `This is a {car_make} {car_model}`
*
* For example, if getCarInfoByIndex is invoked with the inventory and the number 0,
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoByIndex(inventory, index) {
/* code here */
}
/**
* ### Challenge `getLastCarInfo`
*
* @instructions
* getLastCarInfo takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getLastCarInfo returns a string in the format `This is a {car_make} {car_model}
*
* For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js,
* it will return `This is a Lincoln Town Car`.
*/
function getLastCarInfo(/* code here */) {
/* code here */
}
/**
* ### Challenge `getModelYears`
*
* @instructions
* We need the years from every car in the inventory!
* getModelYears takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getModelYears returns an array containing all the 'car_year's in the inventory.
*/
function getModelYears(/* code here */) {
/* code here */
}
/**
* ### Challenge `getCarInfoById`
* * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER
* COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY!
*
* @instructions
* getCarInfoById takes two arguments:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired car id (see how each car has its own unique id).
* getCarInfoById returns a string in the format `This is a {car_make} {car_model}
*
* For example, if getCarInfoById is invoked with the inventory and the number 1,
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoById(/* code here */) {
/* code here */
}
/**
* ### Challenge `getOlderCars`
* * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER
* COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY!
*
* @instructions
* We need a utility to find older cars!
* getOlderCars takes two arguments:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired max year.
* getOlderCars returns an array containing all the cars
* with a `car_year` which is at most the given desired max year,
* in the same order as they appear in the original inventory.
*/
function getOlderCars(/* code here */) {
/* code here */
}
/**
* ### Challenge `getGermanCars`
* * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER
* COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY!
*
* @instructions
* We need a utility to find German cars!
* getGermanCars takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getGermanCars returns an array containing all the cars
* made by either `Audi` or `Mercedes-Benz` or `Volkswagen` or `BMW`,
* in the same order as they appear in the original inventory.
*/
function getGermanCars(/* code here */) {
/* code here */
}
/**
* ### Challenge `carMaker`
* THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER
* COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY!
*
* @instructions
* This function takes a single odometer argument (a number) and returns an object.
* The returned object has the following characteristics:
* it has an `odometer` property that contains the argument passed in.
* it has a `drive` method that takes a distance as its argument, and
* (1) causes the odometer in the object to be increased by the distance,
* (2) returns the updated value of the `odometer`.
*/
function carMaker(/* code here */) {
/* code here */
}
/// ////// END OF CHALLENGE /////////
/// ////// END OF CHALLENGE /////////
/// ////// END OF CHALLENGE /////////
if (typeof exports !== 'undefined') {
// IGNORE: Test/Env Detected
// For Node/Non-browser test env
module.exports = module.exports || {}
if (addNumbers) { module.exports.addNumbers = addNumbers }
if (sayGoodbye) { module.exports.sayGoodbye = sayGoodbye }
if (temperatureCtoF) { module.exports.temperatureCtoF = temperatureCtoF }
if (temperatureInF) { module.exports.temperatureInF = temperatureInF }
if (makePersonObject) { module.exports.makePersonObject = makePersonObject }
if (getName) { module.exports.getName = getName }
if (appleIndex) { module.exports.appleIndex = appleIndex }
if (isItAnApple) { module.exports.isItAnApple = isItAnApple }
if (carMaker) { module.exports.carMaker = carMaker }
if (getCarInfoByIndex) { module.exports.getCarInfoByIndex = getCarInfoByIndex }
if (getLastCarInfo) { module.exports.getLastCarInfo = getLastCarInfo }
if (getCarInfoById) { module.exports.getCarInfoById = getCarInfoById }
if (getModelYears) { module.exports.getModelYears = getModelYears }
if (getOlderCars) { module.exports.getOlderCars = getOlderCars }
if (getGermanCars) { module.exports.getGermanCars = getGermanCars }
}