-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
119 lines (94 loc) · 3.1 KB
/
main.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
113
114
115
116
117
118
119
const header = document.querySelector(".header");
const main = document.querySelector(".main");
const footer = document.querySelector(".footer");
const optionsWrapper = document.createElement("div");
optionsWrapper.setAttribute("class", "options-wrapper");
header.appendChild(optionsWrapper);
const currentDate = document.createElement("p");
currentDate.setAttribute("class", "current-date");
optionsWrapper.appendChild(currentDate);
const modeBtn = document.createElement("button");
modeBtn.setAttribute("class", "mode-btn");
modeBtn.classList.add("btn");
modeBtn.innerText = "* Change Mode *";
optionsWrapper.appendChild(modeBtn);
const greeting = document.createElement("p");
greeting.setAttribute("class", "greeting");
header.appendChild(greeting);
let counter = document.createElement("div");
counter.setAttribute("class", "counter");
main.appendChild(counter);
const btnsWrapper = document.createElement("div");
btnsWrapper.setAttribute("class", "btns-wrapper");
main.appendChild(btnsWrapper);
const downBtn = document.createElement("button");
downBtn.setAttribute("class", "btn");
downBtn.innerText = "< DOWN >";
btnsWrapper.appendChild(downBtn);
const resetBtn = document.createElement("button");
resetBtn.setAttribute("class", "btn");
resetBtn.innerText = "< RESET >";
btnsWrapper.appendChild(resetBtn);
const upBtn = document.createElement("button");
upBtn.setAttribute("class", "btn");
upBtn.innerText = "< UP >";
btnsWrapper.appendChild(upBtn);
//date
const generateCurrentDate = () => {
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
let fullDate = new Date();
let date = fullDate.getDate().toString().padStart(2, "0");
let month = fullDate.getMonth();
let year = fullDate.getFullYear();
let hour = fullDate.getHours().toString().padStart(2, "0");
let minutes = fullDate.getMinutes().toString().padStart(2, "0");
let seconds = fullDate.getSeconds().toString().padStart(2, "0");
return `${date} ${months[month]} ${year} -- ${hour}:${minutes}:${seconds}`;
};
const assignCurrentDate = () => {
currentDate.innerText = generateCurrentDate();
};
setInterval(assignCurrentDate, 1000);
//greeting
let generateGreeting = () => {
let date = new Date();
let hour = date.getHours();
if (hour >= 5 && hour < 13) greeting.innerText = "- Good Morning -";
else if (hour >= 13 && hour < 18) greeting.innerText = "- Good Afternoon -";
else if (hour >= 18 && hour < 22) greeting.innerText = "- Good Evening -";
else if (hour >= 22 && hour < 5) greeting.innerText = "- Good Night -";
else greeting.innerText = "- Good Day -";
};
generateGreeting();
//mode
modeBtn.addEventListener("click", () => {
document.body.classList.toggle("dark");
});
//counter
let counterValue = 0;
counter.innerText = counterValue;
downBtn.addEventListener("click", () => {
counterValue--;
counter.innerText = counterValue;
});
upBtn.addEventListener("click", () => {
counterValue++;
counter.innerText = counterValue;
});
resetBtn.addEventListener("click", () => {
counterValue = 0;
counter.innerText = counterValue;
});