-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer.js
More file actions
78 lines (65 loc) · 1.87 KB
/
Copy pathanswer.js
File metadata and controls
78 lines (65 loc) · 1.87 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
// Question No. 1
function describeValue(val) {
return `${typeof val} | ${val ? "truthy" : "falsy"}`;
}
// Question No. 2
function getDayType(day) {
let dayLowercase = day.toLowerCase();
switch (dayLowercase) {
case "friday":
case "saturday":
return "Weekend";
case "sunday":
case "monday":
case "tuesday":
case "wednesday":
case "thursday":
return "Working Day";
default:
return "Invalid Day";
}
}
// Question No. 3
function validateUsername(username) {
if (username.length < 4)
return "Too Short";
else if (username.includes(" "))
return "No Space Allowed";
else if (username.toLowerCase().includes("admin"))
return "Reserved Word";
else
return "Available";
}
// Question No. 4
function getCngFare(distance, isNight = false, waitingMinutes = 0) {
let fare = 0;
if (distance > 2) {
fare = 50 + (distance - 2) * 15 + waitingMinutes * 2;
if (isNight)
return fare + fare * 20 / 100;
return fare;
} else {
fare = 50 + waitingMinutes * 2;
if (isNight)
return fare + fare * 20 / 100;
return fare;
}
}
// Question No. 5
const getChaseVerdict = (target, scored, ballsLeft) => {
let runsNeeded = target - scored;
let requiredRate;
if (runsNeeded <= 0)
return "Won";
else if (ballsLeft <= 0)
return "Lost";
else {
requiredRate = (runsNeeded / ballsLeft) * 6;
if (requiredRate <= 6)
return `Need ${runsNeeded} runs in ${ballsLeft} balls | Comfortable`;
else if (requiredRate > 6 && requiredRate <= 12)
return `Need ${runsNeeded} runs in ${ballsLeft} balls | Tough`;
else
return `Need ${runsNeeded} runs in ${ballsLeft} balls | Almost Impossible`;
}
};