forked from code-differently/RR-JS-Basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformulas.js
More file actions
415 lines (259 loc) · 8.98 KB
/
formulas.js
File metadata and controls
415 lines (259 loc) · 8.98 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// Basic math formulaas
// code for addition
function addition(num1, num2){
return -1;
}
// ex 1
function addition(num1, num2){
let answer = num1 + num2;
console.log(answer);
}
addition (5,10);
// ex 2
function add(num1, num2) {
let answer = num1 + num2;
return answer;
}
let solution = add(6,3);
console.log(solution);
// ex 3
function adding(num1,num2) {
return num1 + num2;
}
console.log(adding(6,3));
// end code for addition
// Code for Subtraction
function subtraction(num1, num2){
return -1;
}
// ex 1
function subtraction(num1, num2){
let answer = num1 - num2;
console.log(answer);
}
subtraction (10,5);
// ex 2
function subtract(num1, num2){
let answer = num1 - num2;
return answer;
}
let solution = subtract(10,5);
console.log(solution);
// ex 3
function subing(num1, num2) {
return num1 - num2;
}
console.log(subing(10,5));
// End code for subtraction
// Code for multiplication
function multiplication(num1, num2){
return -1;
}
// ex 1
function multiplication(num1, num2){
let answer = num1 * num2;
console.log(answer);
}
multiplication(10,5);
// ex 2
function multiply(num1, num1){
let answer = num1 * num2;
return answer;
}
let solution = multiply(5,10);
console.log(solution);
// ex 3
function multiplying(num1, num2) {
return num1 * num2;
}
console.log(multiplying(10,5));
// end of code
// Code for Division
function division(num1, num2){
return -1;
}
// ex
function division(num1, num2) {
return num1 / num2;
}
console.log(division(10,5));
// end of code
// Area formulaas
// Code for Square
function areaSquare(side){
return -1;
}
// ex
function areaSquare(side) {
let answer = (Math.pow(side));
console.log(Math.pow(side, 2));
}
areaSquare(4);
// not working
function areaSquare (side); {
return Math.pow(side, 2);
}
console.log(areaSquare(4));
// not working
// end of code
// Code areaRectangle
function areaRectangle(length, width){
return -1;
}
// ex
function areaRectangle(num1, num2) {
return num1 * num2;
}
console.log(areaRectangle (4,5));
// end of code
// Code for Parallilogram
function areaParallelogram(base, height){
return -1;
}
// ex
function areaParallelogram(num1, num2) {
return num1 * num2;
}
console.log(areaParallelogram (5, 10));
// end of code
// Code for Triangle Area
function areaTriangle(base, height){
return -1;
}
// ex
function areaTriangle (base, height) {
let answer = (base * height) / (2);
console.log(answer);
}
areaTriangle(20,12);
// end of code
// Code for Circle Area
function Circle(radius){
return -1;
}
// ex
function circle(radius) {
let answer = Math.PI * Math.pow(radius, 2);
console.log(Math.PI * (Math.pow(radius, 2)));
}
circle(20);
// end of code
// Sphere Area
function Sphere(radius){
return -1;
}
// ex
function sphere (radius) {
let answer = 4 * (Math.PI * (Math.pow(radius, 2)));
console.log(4 * (Math.PI * (Math.pow(radius, 2))));
}
sphere(20);
// End of code
// Surface Area formulas
// Cube Surface Area
function surfaceAreaCube(side){
return -1;
}
// ex
function surfaceAreaCube(side) {
let answer = 6 * (Math.pow(side, 2));
console.log(6 * (Math.pow(side, 2)));
}
surfaceAreaCube(20);
// End of code
// Cylinder Surface Area
function surfaceAreaCylinder(radius, height){
return -1;
}
// ex
function surfaceAreaCylinder(radius, height) {
let answer = 2 * (Math.PI * radius * height) + 2 * Math.PI * (Math.pow(radius, 2));
console.log(2 * (Math.PI * radius * height) + 2 * Math.PI * (Math.pow(radius, 2)));
}
surfaceAreaCylinder(20,30);
// end of code
// Perimeter formulas
// Square Perimeter
function perimeterSquare(side){
return -1;
}
// ex
function perimeterSquare(side) {
let answer = 4 * side;
console.log(4 * side);
}
perimeterSquare(20);
// end of code
// Rectangle Perimeter
function perimeterRectangle(length, height){
return -1;
}
// ex
function perimeterRectangle(length, height) {
let answer = 2 * (length + height);
console.log (2 * (length + height));
}
perimeterRectangle (30, 10);
// end of code
// Triangle Perimeter
function perimeterTriangle(side1, side2, side3){
return -1;
}
// ex
function perimeterTriangle(side1, side2, side3) {
let answer = side1 + side2 + side3;
console.log (side1 + side2 + side3);
}
perimeterTriangle(5,15,11);
// end of code
// Circle Perimeter
function perimeterCircle(diameter){
return -1;
}
// ex
function perimeterCircle(diameter) {
let answer = Math.PI * diameter;
console.log (Math.PI * diameter);
}
perimeterCircle(10);
// I looked up the Perimeter Circle Formula and found this. I wasn't sure which was the correct formula so I did both --> C = 2 π r
// function perimeterCircle(radius) {
// let answer = 2 * Math.PI * radius;
// console.log (2 * Math.PI * radius);
// }
// perimeterCircle(10);
// end of code
// Volume formulas
// Cube Volume
function volumeCube(side){
return -1;
}
// ex
function volumeCube(side) {
let answer = Math.pow(side, 3);
console.log(Math.pow(side, 3));
}
volumeCube(12);
// end of code
// Rectangular Volume
function volumeRectangular(length, width, height){
return -1;
}
// ex
function volumeRectangular(length, width, height) {
let answer = length * width * height;
console.log(length * width * height);
}
volumeRectangular(10, 7, 9);
// end of code
// Cylinder Volume
function volumeCylinder(radius, height){
return -1;
}
// ex
function volumeCylinder(radius, height) {
let answer = Math.PI * Math.pow(radius, 2) * height;
console.log(Math.PI * Math.pow(radius, 2) * height);
}
volumeCylinder(5,20);
// end of code