-
Notifications
You must be signed in to change notification settings - Fork 271
/
exercises.js
277 lines (214 loc) · 8.4 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
/*
* A function is a block of code (a series of instructions) designed to execute a certain task. Functions allow you to reuse code.
* i.e. A function to generate a greeting to specific person you designate:*/
// Step One: Define the function.
function greeting(guest){ // takes in a parameter named 'guest' which acts like a local variable inside the function
return "Good afternoon " + guest + "."; // the output value after the function is invoked
}
greeting("Mr. Smith"); // invoking or calling the function to execute the code (instructions) inside the function.
// Step Two: Assign the function invocation to a variable.
var testGreeting = greeting("Mr. Smith"); // assigning the function call into a variable
// Step Three: Console.log the variable to test function output!
console.log(testGreeting); // printing the output value of the function.
// From your terminal, try running this file with node in order to see the result of `console.log(testGreeting);`
/*Below are some specifications for Functions to be built. */
/*
* #1
* Declare two variables
* @variable Datatype: Number `bango1`
* @variable Datatype: Number `bango2`
*
* These two variables will be used to invoke the functions #2 - #5.
*/
/*
* #2
* Function - add
* Create a function named `add` which will take two parameters: `num1` and `num2`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @return Datatype: Number
*
* This function will add two numbers (the parameters, `num1` and `num2`) and
* return the sum of these two numbers.
* Invoke the function and assign it to a variable named `sum`.
* Console.log `sum` to test your code.
*/
/*
* #3
* Function - subtract
* Create a function named `subtract` which will take two parameters: `num1` and `num2`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @return Datatype: Number
*
* This function will subtract two numbers and return the difference of these two numbers.
* Invoke the function and assign it to a variable named `difference`.
* Console.log `difference` to test your code.
*/
/*
* #4
* Function - multiply
* Create a function named `multiply` which will take two parameters: `num1` and `num2`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @return Datatype: Number
*
* This function will multiply two numbers and return the product of these two numbers.
* Invoke the function and assign it to a variable named `product`.
* Console.log `product` to test your code.
*/
/*
* #5
* Function - divide
* Create a function named `divide` which will take two parameters: `num1` and `num2`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @return Datatype: Number
*
* This function will divide two numbers and return the quotient of these two numbers.
* Invoke the function and assign it to a variable named `quotient`.
* Console.log `quotient` to test your code.
*/
/*
* #6
* Function - checkSum
* Create a function named `checkSum` which will take a parameter: `x`.
*
* @param Datatype: Number `x`
* @return Datatype: String
*
* This function will return the string "Mariah Carey has been married `x` amount of times." Where `x` is the value when you invoke the function. Invoke this function using the variable `daDiva`.
* Console.log your result.
*/
/*
* #7
* Function - checkDifference
* Create a function named `checkDifference` which will take a parameter `x`.
*
* @param Datatype: Number `x`
* @return Datatype: String
*
* This function will return the string "Last night I dreamt that I ate `x` Taco Bell soft tacos." Where `x` is the value when you invoke the function. Invoke this function using the variable `difference`.
* Console.log your results.
*/
/*
* #8
* Function - checkProduct
* Create a function named `checkProduct` which does not require any parameters.
*
* @return Datatype: Number
*
* This function will multiply the values stored in the sum and product variables.
* Console.log your result.
*/
/*
* #9
* Function - checkQuotient
* Create a function named `checkQuotient` which does not require any parameters.
*
* @return Datatype: Number
*
* This function will multiply the values stored in the product and quotient variables.
* Console.log your result.
*/
/*
* Declare three variables
* @variable Datatype: Number `bango3`
* @variable Datatype: Number `bango4`
* @variable Datatype: Number `bango5`
* #10
* Function - addThenSubtract
*
* Next, create a function named addThenSubtract which takes three parameters: `num1`, `num2`, `num3`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @param Datatype: Number `num3`
* @return Datatype: Number
*
* This function will add the first two parameters together. Then with the sum of that operation, subtract it from the third parameter. PLEASE USE YOUR PREVIOUS FUNCTIONS FOR THIS EXERCISE.
* Console.log your result.
*/
/*
* #11
* Function - multiplyThenDivide
* Create a function named multiplyThenDivide which takes three parameters: `num1`, `num2`, `num3`.
*
* @param Datatype: Number `num1`
* @param Datatype: Number `num2`
* @param Datatype: Number `num3`
* @return Datatype: Number
*
* This function will multiply the first two parameters together. Then with the product of that operation, divide it from the third parameter. PLEASE USE YOUR PREVIOUS FUNCTIONS FOR THIS EXERCISE.
* Console.log your result.
*/
/*
* #12
* Function - createFullName
* Create a function named createFullName which takes two parameters: `firstName`, `lastName`.
*
* @param Datatype: String `firstName`
* @param Datatype: String `lastName`
* @return Datatype: String
*
* This function `returns` back a string which represents someone's full name. Invoke this function by passing in your first and last name into the function. Store the return value into a variable named `myFullName` and console.log this variable to show your result.
*/
/*
* #13
* Function - eatFood
* Create a function named eatFood which takes three parameters: `firstName`, `lastName`, `food`.
*
* @param Datatype: String `firstName`
* @param Datatype: String `lastName`
* @param Datatype: String `food`
* @return Datatype: String
*
* This function will use the previous `createFullName` function above to create a message. For example, if you invoked the function like this: eatFood("Biggie", "Smalls", "Won Ton Soup"); it will display the message "Biggie Smalls eats Won Ton Soup everyday for breakfast."
* Console.log your result.
*/
/************** ENGAGE HYPERDRIVE **************/
/* No more training wheels! For the exercises #14-18, use the experience you've
* gained figure out how to build the necessary functions. Use your google-fu to
* figure out anything you don't know! Ganbatte (good luck)! */
/************** FIRE ALL CANNONS ***************/
/*
* #14
* Function shoeSize
* Create a function that will take in a parameter named `inches`. This function will convert inches to centimeters(cm).
* Console.log your result.
*/
/*
* #15
* Function allCaps
* Create a function that will take in a parameter named `str`.
* This function will capitalize all the letters in the string.
* Console.log your result.
* Example input: "believe you can and you're halfway there."
* Example output: "BELIEVE YOU CAN AND YOU'RE HALFWAY THERE."
*/
/*
* #16
* Function oneCap
* Create a function that will take in a parameter named `str`.
* This function will capitalize only the first letter in the variable phase above.
* Console.log your result.
*/
/*
* #17
* Function - verifyDrinkingAge
* Create a function named verifyDrinkingAge which takes a parameter named `age`.
* This function returns a Boolean value, `true` or `false`, depending on
* whether `age` is above or below the legal drinking age in the state of Hawaii.
*
* Call this function and pass in a number value.
* Store the return value to a variable named `canDrink`. Console.log your result.
*/
/**
* #18
* Function - throwParty
* Create a function named throwParty. This function will check the value stored in the `canDrink` variable in the previous exercise. If the value is true, it will return the message "Cheee Hoo! We going to da party!" If false, then it will return the message "Meh, see you at Starbucks." Store the return value to a variable named `canParty`. Console.log your result.
*/