/
area-calculator.js
32 lines (27 loc) · 990 Bytes
/
area-calculator.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
function calculateRectangleArea(length,width) {
if (length > 0 && width > 0) {
return length * width
}
return undefined
}
function calculateTriangleArea(base,height) {
if (base > 0 && height > 0) {
return base * height / 2
}
return undefined
}
function calculateCircleArea(radius) {
if (radius < 0) {
return undefined
}
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