-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetInterval.html
More file actions
36 lines (33 loc) · 1007 Bytes
/
setInterval.html
File metadata and controls
36 lines (33 loc) · 1007 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
<!DOCTYPE html>
<html>
<head>
<title>setInterval test</title>
</head>
<body>
<div>
A count down timer using javascript setInterval.
</div>
<div id="status"></div>
<script>
var MyMod = (function () {
// You can also put the coundDown function implementation inside the setInterval function call.
function countDown(seconds) {
var countDownId = setInterval(function () {
if (seconds > -1) {
document.getElementById("status").innerHTML = "Time left: " + seconds;
seconds--;
}
else {
clearInterval(countDownId);
console.log("seconds:", seconds);
}
}, 1000);
}
return {
countDown: countDown,
}
})();
MyMod.countDown(5);
</script>
</body>
</html>