/
areacalc.js
34 lines (29 loc) · 1 KB
/
areacalc.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
function calculateRectangleArea(length, width) {
if (length < 0 || width < 0) {
return undefined;
}
else {
return (length * width);
}
}
function calculateTriangleArea(base, height) {
if (base < 0 | height < 0) {
return undefined;
}
return ((base * height) / 2);
}
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