-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
160 lines (130 loc) · 3.94 KB
/
clock.js
File metadata and controls
160 lines (130 loc) · 3.94 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var wakeuptime = 7;
var noon = 12;
var lunchtime = 12;
var naptime = lunchtime + 2;
var partytime;
var evening = 18;
var showCurrentTime = function()
{
// display the string on the webpage
var clock = document.getElementById('clock');
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var meridian = "AM";
// Set hours
if (hours >= noon)
{
meridian = "PM";
}
if (hours > noon)
{
hours = hours - 12;
}
// Set Minutes
if (minutes < 10)
{
minutes = "0" + minutes;
}
// Set Seconds
if (seconds < 10)
{
seconds = "0" + seconds;
}
// put together the string that displays the time
var clockTime = hours + ':' + minutes + ':' + seconds + " " + meridian + "!";
clock.innerText = clockTime;
};
// Getting the clock to increment on its own and change out messages and pictures
var updateClock = function()
{
var time = new Date().getHours();
var messageText;
var image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/08/normalTime.jpg";
var timeEventJS = document.getElementById("timeEvent");
var lolcatImageJS = document.getElementById('lolcatImage');
if (time == partytime)
{
image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/08/partyTime.jpg";
messageText = "Let's party!";
}
else if (time == wakeuptime)
{
image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat1.jpg";
messageText = "Wake up!";
}
else if (time == lunchtime)
{
image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat2.jpg";
messageText = "Let's have some lunch!";
}
else if (time == naptime)
{
image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat3.jpg";
messageText = "Sleep tight!";
}
else if (time < noon)
{
image = "https://pbs.twimg.com/profile_images/378800000532546226/dbe5f0727b69487016ffd67a6689e75a.jpeg";
messageText = "Good morning!";
}
else if (time >= evening)
{
image = "https://upload.wikimedia.org/wikipedia/commons/8/8c/Cat_sleep.jpg";
messageText = "Good evening!";
}
else
{
image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/08/normalTime.jpg";
messageText = "Good afternoon!";
}
console.log(messageText);
timeEventJS.innerText = messageText;
lolcatImage.src = image;
showCurrentTime();
};
updateClock();
// Getting the clock to increment once a second
var oneSecond = 1000;
setInterval( updateClock, oneSecond);
// Getting the Party Time Button To Work
var partyButton = document.getElementById("partyTimeButton");
var partyEvent = function()
{
if (partytime < 0)
{
partytime = new Date().getHours();
partyTimeButton.innerText = "Party Over!";
partyTimeButton.style.backgroundColor = "#0A8DAB";
}
else
{
partytime = -1;
partyTimeButton.innerText = "Party Time!";
partyTimeButton.style.backgroundColor = "#222";
}
};
partyButton.addEventListener("click", partyEvent);
partyEvent();
// Activates Wake-Up selector
var wakeUpTimeSelector = document.getElementById("wakeUpTimeSelector");
var wakeUpEvent = function()
{
wakeuptime = wakeUpTimeSelector.value;
};
wakeUpTimeSelector.addEventListener("change", wakeUpEvent);
// Activates Lunch selector
var lunchTimeSelector = document.getElementById("lunchTimeSelector");
var lunchEvent = function()
{
lunchtime = lunchTimeSelector.value;
};
lunchTimeSelector.addEventListener("change", lunchEvent);
// Activates Nap-Time selector
var napTimeSelector = document.getElementById("napTimeSelector");
var napEvent = function()
{
naptime = napTimeSelector.value;
};
napTimeSelector.addEventListener("change", napEvent);