-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
118 lines (92 loc) · 2.62 KB
/
app.js
File metadata and controls
118 lines (92 loc) · 2.62 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
console.log('hey there')
/**
*
* The Project
* -----------
* Timer
* 1) Create a timer that captures the time and shows the
* exact current time by second
* //1- capture the current each second, minute, hour of current time
* //2- put current time in code
*
* 2) when click, second changes from number to
* alphabet
*
* Visual Effects
* >> Timer changes colors every seconds
* starts at red, ends at light green
*
*
* >> bottom border grows outward with each second
*
*
*
*/
Array.prototype.contains = function (locateMe) {
for (i in this) {
if (this[i] == locateMe) return true;
}
return false;
}
//listens for 'click' event and toggles clickStatus to on/off
var clickStatus = 'off'
document.querySelector('.timer-box').addEventListener("click",
function(){
clickStatus == 'on' ?
clickStatus ='off' :
clickStatus = 'on'
})
// interval function to get the time and display every second
setInterval(function(){
var d = new Date
//captures the hours/minutes/seconds in one object
var currentTime = new Object
currentTime.hour = d.getHours()
currentTime.minute = d.getMinutes()
currentTime.second = d.getSeconds()
//maps second to alphabet
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var secondsToAlphabet = alphabet[currentTime.second % 26]
var showLetter = "0"+secondsToAlphabet
//line 66-82: puts the hours/minutes/seconds-or-Letters into the html
document.querySelector('.hour').innerHTML =
(currentTime.hour < 10 ? "0" + currentTime.hour : currentTime.hour)
document.querySelector('.minute').innerHTML =
(currentTime.minute < 10 ? "0" + currentTime.minute : currentTime.minute)
//puts seconds or letters, depending on clickStatus
switch (clickStatus)
{
case "on": document.querySelector('.second').innerHTML =
showLetter
break
default:
document.querySelector('.second').innerHTML =
(currentTime.second < 10 ? "0" + currentTime.second : currentTime.second)
break
}
//monitors seconds to determine border-div width - gives effect of growing border
document.querySelector('.line').style.width = (currentTime.second/60*100+"%")
//the background change effect
// - colorTimes determines the timing of color change
// - bgColors determines the color
var colorTimes = [
10,
20,
30,
40,
50,
00
]
var bgColors = [
"133,133,0",
"75,133,88",
"99,100,175",
"100,75,60",
"11,33,145",
"171,11,0"
]
if(colorTimes.contains(currentTime.second)){
var bgIndex = [colorTimes.indexOf(currentTime.second)]
document.querySelector('.container').style.background = "rgb("+bgColors[bgIndex]+")"
}
},1000)