-
Notifications
You must be signed in to change notification settings - Fork 0
/
BD1.3_HW_1.js
112 lines (103 loc) · 2.38 KB
/
BD1.3_HW_1.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
let express = require("express");
let app = express();
let port = 3000;
// Question 1
app.get("/check-whole-number", (req, res) => {
let number = parseFloat(req.query.number);
let result;
if (number >= 0) {
result = "Number is whole number";
} else {
result = "Number is not whole";
}
res.send(result);
});
// Question 2
app.get("/check-equal", (req, res) => {
let num1 = parseFloat(req.query.num1);
let num2 = parseFloat(req.query.num2);
let result;
if (num1 === num2) {
result = "Numbers are equal";
} else {
result = "Numbers are not equal";
}
res.send(result);
});
// Question 3
app.get("/check-active", (req, res) => {
let isActive = req.query.isActive === "true";
let result = "";
if (isActive) {
result = "User is active";
} else {
result = "User is not active";
}
res.send(result);
});
// Question 4
app.get("/check-discount", (req, res) => {
let cost = parseFloat(req.query.cost);
let result;
if (cost > 1000) {
result = "User is eligible for discount";
} else {
result = "User is not eligible for discount";
}
res.send(result);
});
// Question 5
app.get("/check-experience", (req, res) => {
let workExperience = parseFloat(req.query.workExperience);
let result;
if (workExperience > 0) {
result = "Person is experienced";
} else if (workExperience < 0) {
result = "Person is non-working";
} else {
result = "Person is a fresher";
}
res.send(result);
});
// Question 6
app.get("/check-result", (req, res) => {
let result = parseFloat(req.query.result);
let grade;
if (result > 80) {
grade = "A";
} else if (result >= 50) {
grade = "B";
} else {
grade = "Fail";
}
res.send("The grade is " + grade);
});
// Question 7
app.get("/check-attendance", (req, res) => {
let attendance = parseInt(req.query.attendance);
let result;
if (attendance < 50) {
result = "low";
} else if (attendance <= 90) {
result = "moderate";
} else {
result = "high";
}
res.send("Attendance is " + result);
});
// Question 8
app.get("/check-rating", (req, res) => {
let stars = parseInt(req.query.stars);
let result;
if (stars < 3) {
result = "low";
} else if (stars <= 4) {
result = "moderate";
} else {
result = "high";
}
res.send("Restaurant rating is " + result);
});
app.listen(port, () => {
console.log("Server is running on http://localhost:" + port);
});