-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
18 lines (16 loc) · 839 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var width = 12; // width variable
function calculateArea (width, height) {
try {
var area = width * height; // Try to calculate area
if (!isNaN(area)) { // If it is a number
return area; // Return the area
} else { // Otherwise throw an error
throw new Error('calculateArea() received invalid number');
}
} catch (e) { // If there was an error
console.log(e.name + ' ' + e.message); // Show error in console
return 'We were unable to calculate the area.'; // Show users a message
}
}
// TRY TO SHOW THE AREA ON THE PAGE
document.getElementById('area').innerHTML = calculateArea(width, height);