-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
38 lines (28 loc) · 885 Bytes
/
main.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
var names = ["李华","小明","小红","小张","HXD","LPL","LOL"];
var length = names.length;
var displayBoard = document.getElementById("nameDisplay");
mytime = null
function clickButton(btn) {
var text = btn.innerHTML;
console.log(text);
if (text == "Start") {
btn.innerHTML = "End";
if (mytime == null) {
mytime = setInterval(function () {
var name = randomName();
console.log(name);
displayBoard.innerHTML = name;
}, 100);
}
} else if (text == "End") {
btn.innerHTML = "Start";
if (mytime != null) {
clearInterval(mytime);
mytime = null;
}
}
}
function randomName() {
var randomNum = Math.ceil(Math.random() * 4000) % length + 1;
return names[randomNum - 1];
}