-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
33 lines (26 loc) · 1.04 KB
/
Copy pathrender.js
File metadata and controls
33 lines (26 loc) · 1.04 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
const clockDisplay = document.getElementById('clock');
let catBttn = document.querySelector('#changeCatBg');
catBttn.addEventListener('click', () => {
var number = Math.floor(Math.random() * 12) + 1;
var filepath = "url(cat" + number + ".jpg)";
document.body.style.backgroundImage = filepath;
});
function updateClock() {
const currentDate = new Date();
if ((currentDate.getMinutes() == 59) && (currentDate.getSeconds() == 59)) {
var number = Math.floor(Math.random() * 12) + 1;
var filepath = "url(cat" + number + ".jpg)";
document.body.style.backgroundImage = filepath;
}
const secondsRatio = formatTime(currentDate.getSeconds());
const minutesRatio = formatTime(currentDate.getMinutes());
const hoursRatio = formatTime(currentDate.getHours());
clockDisplay.innerText=`${hoursRatio} : ${minutesRatio} : ${secondsRatio}`;
};
function formatTime (time) {
if ( time < 10 ) {
return '0' + time;
}
return time;
};
setInterval(updateClock, 1000);