-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
78 lines (71 loc) · 1.4 KB
/
scripts.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
// const compliment=document.getElementById('compliment');
// function getCompliment()
// {
// fetch('https://complimentr.com/api')
// .then(res => res.json())
// .then(data =>
// {
// compliment.innerHTML='${data.compliment}'
// })
// }
window.onload=initClock();
function fetchData()
{
fetch("https://complimentr.com/api")
.then(response => {
return response.json();
})
.then(data=>
{
console.log(data.compliment);
document.getElementById('compliment').innerHTML= data.compliment;
}
)
}
fetchData();
function updateClock()
{
var now= new Date();
var
mo=now.getMonth(),
dnum=now.getDate(),
yr=now.getFullYear(),
h=now.getHours(),
min=now.getMinutes(),
sec=now.getSeconds();
var ids=["month","date","year","hours","mins","secs"] ;
var months=["January","February","March","April","May","June","July","August","September","October","November","December"];
if(sec<10)
{
sec="0"+sec;
}
if(dnum>=11&&dnum<=20)
{
dnum=dnum+"th"
}
else
if(dnum%10==1){
dnum=dnum+"st";
}
else
if(dnum%10==2){
dnum=dnum+"nd";
}
else
if(dnum%10==3){
dnum=dnum+"rd";
}
else {
dnum=dnum+"th"
}
var values=[months[mo] ,dnum,yr,h,min,sec];
for(var i =0;i<6;i++)
{
document.getElementById(ids[i]).innerHTML=values[i];
}
}
function initClock()
{
updateClock();
window.setInterval("updateClock()",1);
}