-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.js
272 lines (191 loc) Β· 8.87 KB
/
index.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
/*ποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈ Task 1: Warm-up! ποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈποΈββοΈ*/
/*MAKE SURE TO RETURN ALL OF THE ANSWERS INSIDE OF A FUNCTION (tasks 1d through task 7), IF YOU DON'T, THE AUTOGRADER WILL NOT WORK*/
// task 1a, 1b, and 1c are not autograded
/*
When doing these tasks, we recommend using console.log to test the output of your code to make sure it works correctly.
This will usually entail console logging the answer directly or console logging the invocation (call) of the function so when it
returns a value, that value will be logged to the console. An example of this would be: console.log(theFunction(value1,value2))
*/
/*
Task 1a - Voting Age (not auto tested)
Do the following:
1. Create a variable called votingAge and assign it a number value
2. Console log true if age is 18 or higher
HINT: no function required
*/
/*
Task 1b - Values (not auto tested)
Do the following:
1. Declare two variables and assign them values (good names for these might be firstThing and secondThing)
2. Use a conditional to check the value of the 1st variable versus the value assigned to the 2nd variable
3. Change the value of the 1st variable if the conditional in step 2 is true
4. Console log the value of the 1st variable
HINT: no function required
*/
/*
Task 1c - Convert Strings to Numbers (not auto tested)
Do the following:
1. Declare a variable with the string type value of "1999"
2. Convert the string value of "1999" to a integer value of 1999
3. Console log the result
HINT: look up the Number method
*/
/*
Task 1d - Multiply
Do the following:
1. Invoke the multiply function below and pass it two numbers
2. Receive the parameters: a and b
3. Multiply a and b and return the answer
*/
function multiply(num1, num2){
return num1 * num2;
}
/*ππππππππππ Task 2 ππππππππππ*/
//Age in Dog years
/*
Do the following:
1. Invoke the dogYears function below and pass an age value to it
2. Use the received value to calculate the age in dog years (1 human year is equal to 7 dog years)
3. Return the newly calculated age
*/
function dogYears(/*add your code here*/){
/*add your code here*/
}
/*ππππππππππ Task 3 ππππππππππ*/
//Dog feeder - Depending on their weight and age, we need to know how many pounds of food to feed our dog each day!
/*
Use the hungryDog function and feeding requirements below to do the following:
1. Invoke the hungryDog function below and pass it a weight value in pounds, followed by an age value in years
2. π NOTE: if the dog is a puppy, the age will be a decimal (rounded to two places). For example: 3 months = .25 (3 divided by 12)
3. Do the proper calculations and return the number of pounds of raw food to feed the dog/puppy in a day
REMEMBER: This program should handle correctly adult AND puppy ages and weights
HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters
Feeding Requirements:
Adult Dogs 1 year and older
up to 5 lbs - 5% of their body weight
6 - 10 lbs - 4% of their body weight
11 - 15 lbs - 3% of their body weight
> 15lbs - 2% of their body weight
Puppies less than 1 year
2 - 4 months 10% of their body weight
4 - 7 months 5% of their body weight
7 - 12 months 4% of their body weight
NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996
NOTE 2: This is a great time to check the tests to see what it expects, versus what is actually
returned from your function. This is an example of the output to look for on each test point.
β hungryDogFunction βΊ Dog is 1 year and is 5lbs or less
expect(received).toBe(expected) // Object.is equality
Expected: 0.2
Received: undefined
21 | describe('hungryDogFunction', ()=>{
22 | it('Dog is 1 year and is 5lbs or less', ()=>{
> 23 | expect(functions.hungryDog(4, 1)).toBe(0.2);
|
^
24 | })
Notice the expected and received, expected is what the test is looking for, and received is what was actually returned from this function. You can also see it's passing in two values, the number 4 and the number 1.
So, on this one test, the weight would be 4 pounds, and the age would be 1 years old. It's expecting your function to return a decimal number of 0.2
*/
function hungryDog(/*add your code here*/){
/*add your code here*/
}
/*ππππππππππ Task 4 ππππππππππ*/
// Rock, Paper, Scissors - Let's play against the computer!
/*
Do the following:
1. Create a new variable that randomly generates the computer's choice, this must not be done inside the function
2. Use Math.random to determine the computer's choice (Math.random gives a random number between 0 and 1)
3. Make a conditional that changes the variable to "rock", "paper", or "scissors" based on it's random number
Use the game function below to do the following:
1. Receive 2 parameters: a string with the user's choice of "rock", "paper", or "scissors"
and the computer's choice of "rock", "paper", or "scissors".
Note: make sure the strings are all lower case or it will not pass the test
2. Return whether the user won, lost, or tied based on these rules of the game described below - the strings returned need to match these strings below exactly.
- win should return "you win!"
- lose should return "you lose!"
- tie should return "it's a tie"
RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie
*/
function game(user, computer){
/*add your code here*/
}
/*ππππππππππ Task 5 ππππππππππ*/
//Metric Converter
//Task 5a - Kilometers to Miles
/*
Using the miles function below do the following:
1. Receive a number of kilometers
2. Convert the number of kiolmeters received to miles
3. Return the number of miles
*/
function miles(/*add your code here*/){
/*add your code here*/
}
//Task 5b - Centimeters to Feet
/*
Using the feet function below do the following:
1. Receive a number of cm
2. Convert the number of cm to feet
3. Return number of feet
*/
function feet(/*add your code here*/){
/*add your code here*/
}
/*ππππππππππ Task 6 ππππππππππ*/
// Let's Sing 99 Bottles of Soda on the Wall!
/*
Using the annoyingSong function below do the following:
1. Receive a starting number
2. The annoying song function should return the following string exactly one time:
"{number you gave as an argument} bottles of soda on the wall, {number you gave as an argument} bottles of soda, take one down pass it around {number you gave as an argument minus 1} bottles of soda on the wall"
3. Outside of the function, Make a loop that invokes annoying song with a number that decreases until it gets to 1 bottle left.
4. Each time the annoyingSong is run from this loop, it should console.log the string that was returned.
*/
function annoyingSong(/*add your code here*/){
/*add your code here*/
}
/*ππππππππππ Task 7 ππππππππππ*/
//Grade Calculator
/*
Using the grade function below do the following:
1. Receive a score out of 100
2. Return the corresponding letter grade following this grade scale:
90-100 should return 'you got an A'
80-89 should return 'you got a B'
70-79 should return 'you got a C'
60-69 should return 'you got a D'
below should return 'you got an F'
*/
function grade(/*Your Code here */){
/*Your Code here */
}
/*πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ Stretch πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ*/
//Vowel Counter - How many vowels are there?
/*
Using the vowelCounter function below do the following:
1. Receive a string as a parameter
2. Count and return the number of vowels within that string. It should handle both capitalized and uncapitalized vowels.
HINT - you may need to study tomorrow's content on arrays
HINT - try looking up the .includes() method
*/
function vowelCounter(/*add your code here*/) {
/*add your code here*/
}
/*ππππππππππ Please do not modify anything below this line ππππππππππ*/
function foo(){
console.log('its working');
return 'bar';
}
foo();
/*ππππππππππ Don't touch the code after this line! ππππππππππ*/
module.exports = {
foo,
multiply,
dogYears,
hungryDog,
game,
miles,
feet,
annoyingSong,
grade
}