-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-shape-areas.js
36 lines (30 loc) · 1.01 KB
/
basic-shape-areas.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
const calculateRectangleArea = function (length, width) {
if(length <= 0 || width <= 0) {
return;
} else {
return length * width;
}
}
const calculateTriangleArea = function (base, height) {
if(base <= 0 || height <= 0) {
return;
} else {
return base * height / 2;
}
}
const calculateCircleArea = function (radius) {
if (radius <= 0) {
return;
} else {
return Math.PI * radius ** 2;
}
}
console.log(calculateRectangleArea(10, 5)); // should print 50
console.log(calculateRectangleArea(1.5, 2.5)); // should print 3.75
console.log(calculateRectangleArea(10, -5)); // should print undefined
console.log(calculateTriangleArea(10, 5)); // should print 25
console.log(calculateTriangleArea(3, 2.5)); // should print 3.75
console.log(calculateTriangleArea(10, -5)); // should print undefined
console.log(calculateCircleArea(10)); // should print 314.159...
console.log(calculateCircleArea(3.5)); // should print 38.484...
console.log(calculateCircleArea(-1)); // should print undefined