-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (74 loc) · 1.97 KB
/
script.js
File metadata and controls
83 lines (74 loc) · 1.97 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Task 1
function testThrow(excemtion) {
try {
throw excemtion;
} catch (error) {
console.log("Caught:" + error);
}
}
testThrow(5);
testThrow(new Error("An error happened"));
// Task 2
/*function calcRectangleArea(heigth, width) {
try {
var area = width * heigth;
area = JSON.parse(area);
console.log("The area of Rectangle is :", area);
} catch (excemtion) {
console.log("Error: Inccorect inpute data");
}
}
calcRectangleArea(5, 8);*/
function calcRectangleArea(width, heigth) {
try {
var area = width * heigth;
if (isNaN(area)) throw "Error: Incorrect Data";
console.log("The area of Rectangle is :", area);
} catch (error) {
console.log(error);
}
}
calcRectangleArea(5, 8);
// Task 3
function checkAge(age) {
var age = prompt("Pleas enter your age", "Age");
try {
if (age == "") throw "The field is empty! Plis enter your age!";
if (isNaN(age)) throw "Error: data is not a number!";
if (age < 14) throw "You must be older then 14!";
console.log("Yuo can whoch this film!");
} catch (excemtion) {
console.log(excemtion);
}
}
checkAge();
// Task 4
class MonthException {
constructor(mesage) {
this.name = "MonthException";
this.mesage = mesage;
}
}
var obj = new MonthException("Incorrect month number");
//console.log(Object.values(x));
function showMonthName(month) {
try {
if (month < 1 || month > 12)
throw obj.name.toString() + " " + obj.mesage.toString();
if (month == 1) return "January";
if (month == 2) return "February";
if (month == 3) return "March";
if (month == 4) return "Aprile";
if (month == 5) return "May";
if (month == 6) return "June";
if (month == 7) return "July";
if (month == 8) return "August";
if (month == 9) return "September";
if (month == 10) return "October";
if (month == 11) return "Novembr";
if (month == 12) return "December";
} catch (excemtion) {
console.log(excemtion);
}
}
console.log(showMonthName(14));