-
Notifications
You must be signed in to change notification settings - Fork 0
/
area-clculators-assignment.js
39 lines (33 loc) · 1.22 KB
/
area-clculators-assignment.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
/*calculateRectangleArea(length, width)
calculateTriangleArea(base, height)
calculateCircleArea(radius)*/
/*rectangle: length × width
triangle: base × height / 2
circle: π × radius2*/
function calculateRectangleArea(length, width) {
if ((length * width) <= 0) {
return undefined
} else {
return (length * width) }
}
function calculateTriangleArea(base, height) {
if ((base * height / 2) <= 0) {
return undefined
} else {
return (base * height / 2) }
}
function calculateCircleArea(radius) {
if ((Math.PI * Math.pow(radius,2) <= 0) {
return undefined
} else {
return (Math.PI * (radius * radius)) }
}
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