How would you convert the time into mintues and seconds?
When I click on the start button the time appears at 300 not 5:00 mintues.
How would you do this?
<!DOCTYPE html>
<html>
<head>
<title>TImer</title>
<script type="text/javascript">
var COUNT = 60*5;
var time, count;
function display() {
// displays time in span
document.getElementById('timespan').innerHTML = count;
};
function countdown() {
// starts countdown
cddisplay();
if (count == 0) {
// time is up
} else {
count--;
time = setTimeout("countdown()", 1000);
}
};
function pause() {
// pauses countdown
clearTimeout(time);
};
function reset() {
// resets countdown
pause();
count = COUNT;
display();
};
</script>
<body onload="reset()">
<span id="timespan"></span>
<input type="button" value="Start" onclick="countdown()">
<input type="button" value="Stop" onclick="pause()">
<input type="button" value="Reset" onclick="reset()">
</body>
</html>
A quick and dirty way would be to divide by 60, integer of that is the minute value, multiply that integer back by sixty and subtract it from the original count for the remaining seconds, or get the seconds from the modulo of the count and sixty.
Another way would be to create a Date object, which provides methods to get the minutes and seconds (among others):
function display () {
var date = new Date(count * 1000)
var timeString = date.getMinutes() + ':' + date.getSeconds()
document.getElementById('timespan').textContent = timeString
}