-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (31 loc) · 835 Bytes
/
Copy pathscript.js
File metadata and controls
37 lines (31 loc) · 835 Bytes
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
function redirectToPage(target) {
console.log(target);
location.href = `${target}.html`;
}
function playAudio(audioID) {
var music = new Audio(`./audio/${audioID}.mp3`);
music.play();
}
function startTimer(duration, display) {
var timer = duration,
minutes,
seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
timer = duration;
redirectToPage("index");
}
}, 1000);
}
window.onload = function () {
if (document.getElementById("count_down")) {
var countDownTime = 5, // 5 seconds
display = document.querySelector("#count_down");
startTimer(countDownTime, display);
}
};