forked from SunJieMing/js-minicamp-homework-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercises.js
246 lines (204 loc) · 5.03 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
//Do not change any of the function names
function multiplyByTen(num) {
var product = num * 10;
return product;
// return num after multiplying it by ten
// code here
}
function subtractFive(num) {
var difference = num - 5;
return difference;
// return num after subtracting five
// code here
}
function areSameLength(str1, str2) {
var str1Length = str1.length;
var str2Length = str2.length;
if (str1Length === str2Length) {
return true;
}
return false;
// return true if the two strings have the same length
// otherwise return false
// code here
}
function areEqual(x, y) {
if (x === y) {
return true;
}
return false;
// return true if x and y are the same
// otherwise return false
// code here
}
function lessThanNinety(num) {
if (num < 90) {
return true;
}
return false;
// return true if num is less than ninety
// otherwise return false
// code here
}
function greaterThanFifty(num) {
if (num > 50) {
return true;
}
return false;
// return true if num is greater than fifty
// otherwise return false
// code here
}
function add(x, y) {
var sum = x + y;
return sum;
// add x and y together and return the value
// code here
}
function subtract(x, y) {
var difference = x - y;
return difference;
// subtract y from x and return the value
// code here
}
function divide(x, y) {
var dividend = x / y;
return dividend;
// divide x by y and return the value
// code here
}
function multiply(x, y) {
var product = x * y;
return product;
// multiply x by y and return the value
// code here
}
function getRemainder(x, y) {
var remainder = x % y;
return remainder;
// return the remainder from dividing x by y
// code here
}
function isEven(num) {
if (num % 2 === 0) {
return true;
}
return false;
// return true if num is even
// otherwise return false
// code here
}
function isOdd(num) {
if (num % 2 === 1) {
return true;
}
return false;
// return true if num is odd
// otherwise return false
// code here
}
function square(num) {
var square = Math.pow(num, 2);
return square;
// square num and return the new value
// code here
}
function cube(num) {
var cube = Math.pow(num, 3);
return cube;
// cube num and return the new value
// code here
}
function raiseToPower(num, exponent) {
var power = Math.pow (num, exponent);
return power;
}
// raise num to whatever power is passed in as exponent
// code here
function roundNumber(num) {
var round = Math.round(num);
return round;
// round num and return it
// code here
}
function roundUp(num) {
var ceiling = Math.ceil(num);
return ceiling;
// round num up and return it
// code here
}
function addExclamationPoint(str) {
var exclamation = str + '!';
return exclamation;
// add an exclamation point to the end of str and return the new string
// 'hello world' -> 'hello world!'
// code here
}
function combineNames(firstName, lastName) {
var name = firstName + ' ' + lastName;
return name;
// return firstName and lastName combined as one string and separated by a space.
// 'Lambda', 'School' -> 'Lambda School'
// code here
}
function getGreeting(name) {
var greeting = 'Hello ' + name + '!';
return greeting;
// Take the name string and concatenate other strings onto it so it takes the following form:
// 'Sam' -> 'Hello Sam!'
// code here
}
// If you can't remember these area formulas then head over to Google or look at the test code.
function getRectangleArea(length, width) {
var areaSquare = length * width;
return areaSquare;
// return the area of the rectangle by using length and width
// code here
}
function getTriangleArea(base, height) {
var areaTriangle = (base * height) / 2;
return areaTriangle;
// return the area of the triangle by using base and height
// code here
}
function getCircleArea(radius) {
var areaCircle = Math.round(Math.pow(radius,2) * 3.14);
return areaCircle;
// return the rounded area of the circle given the radius
// code here
}
function getRectangularPrismVolume(length, width, height) {
var areaRectangularPrism = length * width * height;
return areaRectangularPrism;
// return the volume of the 3D rectangular prism given the length, width, and height
// code here
}
// Do not modify code below this line.
// --------------------------------
module.exports = {
multiplyByTen: multiplyByTen,
subtractFive: subtractFive,
areSameLength: areSameLength,
areEqual: areEqual,
lessThanNinety: lessThanNinety,
greaterThanFifty: greaterThanFifty,
add: add,
subtract: subtract,
divide: divide,
multiply: multiply,
getRemainder: getRemainder,
isEven: isEven,
isOdd: isOdd,
square: square,
cube: cube,
raiseToPower: raiseToPower,
roundNumber: roundNumber,
roundUp: roundUp,
addExclamationPoint: addExclamationPoint,
combineNames: combineNames,
getGreeting: getGreeting,
getRectangleArea: getRectangleArea,
getTriangleArea: getTriangleArea,
getCircleArea: getCircleArea,
getRectangularPrismVolume: getRectangularPrismVolume
};