-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
148 lines (116 loc) · 2.75 KB
/
Copy pathclock.js
File metadata and controls
148 lines (116 loc) · 2.75 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
var wakeUp=8;
var noon=12;
var evening=17;
var lunchTime=13;
var naptime=lunchTime+2;
var partytime;
//console.log('hello');
//clock function
function startTime(){
let time=new Date();
var h=time.getHours();
var m=time.getMinutes();
var s=time.getSeconds();
m=checkTime(m);
s=checkTime(s);
day=DayOrNight(h);
h=clock12(h);
h=checkTime(h);
document.getElementById('onlytime').innerHTML=h +":"+ m +":" + s +" "+ day;
var t=setTimeout(startTime,500);;
}
// to append zeros if minutes hours and seconds are less than 10
function checkTime(i){
if (i<10){
i="0"+i;
}
return i;
}
//to append am or pm with the time
function DayOrNight(i){
if(i<=12 ){
return "Am";
}
else{
return "PM"
}
}
//to convert the 24 hr clock into 12 hr clock
function clock12(h){
if(h>12){
h=h-12;
}
return h;
}
//to load the image according to the time
var updateTime= function () {
let time1=new Date();
var hr=time1.getHours();
console.log(hr);
Img='afternoon.jpeg';
let txt=document.getElementById('text');
let msg;
//image=document.createAttribute('img');
if(hr==wakeUp) {
img='goodmrng';
msg=`"good morning get up"`;
}
else if (hr==lunchTime){
img='food.jpeg';
msg=`"its lunch time"`;
}
else if(hr==naptime){
img= 'nap.jpeg';
msg=`"its nap time"`;
}
else if(hr>evening){
img='evening.jpeg'
msg=`"good evening"`;
}
else if(hr<noon){
img='goodmrng.jpeg';
msg=`"good morning"`;
}
else {
img='afternoon.jpeg';
msg=`"good afternoon"`;
}
image.src=img;
txt.innerText=msg;
}
updateTime();
document.getElementById('wakeup').addEventListener('change',wakeUP);
function wakeUP()
{
let img='goodmrng.jpeg';
msg=`"good morning get up"`;
document.getElementById('image').src=img;
document.getElementById('text').innerText=msg;
}
document.getElementById('lunch').addEventListener('change',Lunch);
function Lunch(){
let img='food.jpeg';
let msg=`"its lunch time"`;
document.getElementById('image').src=img;
document.getElementById('text').innerText=msg;
}
document.getElementById('napTime').addEventListener('click',napTime);
function napTime(){
let img= 'nap.jpeg';
let msg=`"its nap time"`;
document.getElementById('image').src=img;
document.getElementById('text').innerText=msg;
}
document.getElementById('party').addEventListener('click',function(){
if(document.getElementById('party').innerText==`party time!!`){
let img="party.jpeg";
let txt=`"its party time"`;
document.getElementById('image').src=img;
document.getElementById('text').innerText=txt;
document.getElementById('party').innerText=`party over!!`;
}
else{
document.getElementById('party').innerText=`party time!!`;
updateTime();
}
})