-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
102 lines (83 loc) · 1.86 KB
/
sketch.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
var h2 = document.querySelector(".calendar-picture h2");
var h3 = document.querySelector(".calendar-picture h3");
var monthArr = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"Decemeber",
];
var dayArr = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thrusday",
"Friday",
"Saturday",
];
var day31MonthArr = [
"January",
"March",
"May",
"July",
"August",
"October",
"December",
];
var d = new Date();
var obj = getDate();
generateCalendar();
function getDate(){
var month = d.getMonth();
month = monthArr[month]
var day = d.getDay();
day = dayArr[day];
var date = d.getDate();
h2.innerHTML = date+", "+day;
h3.innerHTML = month;
return {m:month, dy:day, dt:date, yr: d.getFullYear()}
}
function generateCalendar(){
var days;
if (obj.m === "February" && obj.yr % 4 !== 0) {
days = 28;
} else if (obj.m === "February" && obj.yr % 4 === 0) {
days = 29;
} else if (day31MonthArr.includes(obj.m)) {
days = 31;
} else {
days = 30;
}
var LocalDayArr = [
"Monday",
"Tuesday",
"Wednesday",
"Thrusday",
"Friday",
"Saturday",
"Sunday"
];
var startOfMonth= moment().clone().startOf("month").format("dddd")
var dayIndex = LocalDayArr.indexOf(startOfMonth);
for(var j=0;j<dayIndex;j++){
var element = document.createElement("div");
element.className = "calendar__number_empty";
document.getElementById("lc").appendChild(element);
}
for(var k = 1; k<=days;k++){
var element = document.createElement("div");
obj.dt === k
?(element.className = "calendar__number calendar__number--current")
:(element.className = "calendar__number");
element.appendChild(document.createTextNode(k));
document.getElementById("lc").appendChild(element);
}
}