-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.js
More file actions
35 lines (31 loc) · 966 Bytes
/
switch.js
File metadata and controls
35 lines (31 loc) · 966 Bytes
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
let dayStatus = document.getElementById("dayStatus");
function checkStatus() {
const dateInput = document.getElementById("checkDate").value;
const date = new Date(dateInput);
const day = date.getDay();
switch (day) {
case 0:
case 1:
case 2:
case 3:
case 4:
dayStatus.innerText = "Working Day";
break;
case 5:
case 6:
dayStatus.innerText = "Weekend";
break;
default:
dayStatus.innerText = "Invalid Date";
}
}
function reset() {
document.getElementById("checkDate").value = "";
dayStatus.innerText = "";
}
/**
* break statement is used to exit the switch case once a match is found.
* Without break, the code would continue to execute the subsequent cases (fall-through behavior).
* default case handles any unexpected input, ensuring robustness.
* switch uses strict comparison (===) for matching cases.
*/