-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.html
More file actions
36 lines (34 loc) · 868 Bytes
/
example.html
File metadata and controls
36 lines (34 loc) · 868 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>
<head>
<title> JS Countdown Example </title>
</head>
<body>
<p class="pull-right">Time left: <span id="timer"><span id="timeLeft">00:00</span></span></p>
<script>
var displayLocation = document.getElementById("timeLeft");
var elapsedTime;
var secconds = 1800;
var counter = setInterval(function () {
"use strict";
counterBegin();
}, 1000);
function counterBegin() {
"use strict";
var minutes = Math.floor(secconds / 60),
secondsLeft = secconds % 60;
if (secondsLeft < 10) {
secondsLeft = '0' + secondsLeft;
}
if (minutes < 10) {
minutes = '0' + minutes;
}
displayLocation.innerHTML = minutes + ":" + secondsLeft;
if (secconds > 0) {
secconds = secconds - 1;
} else {
clearInterval(counter);
}
}
</script>
</body>
</html>