-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (42 loc) · 1.11 KB
/
index.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
// displaying the current month in the header
const monthEl = document.querySelector(".date h1");
const currentMonth = new Date().getMonth();
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
monthEl.innerText = months[currentMonth];
// displaying the current date in the header
const dateEl = document.querySelector(".date p");
const currentDate = new Date().toDateString();
dateEl.innerText = currentDate;
// displaying the actual calendar content
const daysEl = document.querySelector(".days");
const lastDay = new Date(
new Date().getFullYear(),
currentMonth + 1,
0
).getDate();
const firstDay = new Date(new Date().getFullYear(), currentMonth, 1).getDay();
let days = "";
for (let i = firstDay; i > 0; i--) {
days += `<div class="empty"></div>`;
}
for (let i = 1; i <= lastDay; i++) {
if (i === new Date().getDate()) {
days += `<div class='today'>${i}</div>`;
} else {
days += `<div>${i}</div>`;
}
}
daysEl.innerHTML = days;