-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
78 lines (75 loc) · 1.76 KB
/
script.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 showTimer = true;
// Add list of names here
const namesList = [
'Edward',
'Jhonny',
'Jenny',
'Philip',
'Stepa',
'David',
'Charloet',
];
// Default variables
let i = 0;
let x = 0;
let intervalHandle = null;
const startButton = document.getElementById('startButton');
const stopButton = document.getElementById('stopButton');
const headerOne = document.getElementById('headerNames');
// Optional countdown timer
// Add zero in front of numbers < 10
function checkSecond(sec) {
if (sec < 5 && sec >= 0) {
sec = "0" + sec;
}
if (sec < 0) {
sec = "59";
}
return sec;
}
// Start or stop the name shuffle on the button click
startButton.addEventListener('click', function() {
this.style.display = "none";
stopButton.style.display = "block";
intervalHandle = setInterval(function () {
headerNames.textContent = namesList[i++ % namesList.length];
}, 50);
if (showTimer===true) {
timerWrapper.classList.remove('visible');
}
});
stopButton.addEventListener('click', function() {
this.style.display = "none";
startButton.style.display = "block";
clearInterval(intervalHandle);
timer.innerHTML = time;
if (showTimer===true) {
timerWrapper.classList.add('visible');
}
startTimer();
});
// Allow use of spacebar to start/stop name shuffle
document.body.onkeyup = function(e) {
if (e.keyCode == 32) {
if (x%2===0) {
startButton.style.display = "none";
stopButton.style.display = "block";
intervalHandle = setInterval(function () {
headerNames.textContent = namesList[i++ % namesList.length];
}, 50);
if (showTimer===true) {
timerWrapper.classList.remove('visible');
}
} else {
startButton.style.display = "block";
stopButton.style.display = "none";
clearInterval(intervalHandle);
timer.innerHTML = time;
if (showTimer===true) {
timerWrapper.classList.add('visible');
}
startTimer();
}
x++;
}
}