-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.js
27 lines (24 loc) · 1011 Bytes
/
shapes.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
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;
} else return (base * height / 2);
}
function calculateCircleArea(radius) {
if (radius < 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