Im trying to create a small JavaScript timer in which a user has a limited amount of time to answer a question, and if the user does not answer in time, they will be directed back to the main page. All I get back from my code in terms of the timer is literally " [ ] ".
My code:
<DOCTYPE! html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style_q1.css">
<script type="text/javascript">
var time="60";
var min="0";
var sec="0";
function startTimer() {
min=parseInt(timer/60);
sec=parseInt(timer%60);
if(timer<1){
window.location="index.html";
}
document.getElementById("time").innerHTML = "<b> Time Left: </b>"+min.toString()+":"+sec.toString();
timer--;
setTimeout(function(){
startTimer();
}, 1000) ;
}
</script>
</head>
<body onload="startTimer();">
<div id="top">
</div>
<div id="logo">
<h1 style="color:white;"> Question 1 - Geography </h1>
</div>
<div id="game_area">
<center> <h2> What is the capital of Ireland? </h2> </center>
</div>
<div id="time">
<center> <b>[<span id="time" ></span></b>]</center>
</div>
</body>
</html>
timeranywhere.