I tried to add the timer to my code. The problem is the code works perfectly fine when used inside HTML, but when i tried to use it in an external javascript file it is not working. Help me out
I tried using inside HTML code , it works perfect, But not in as a seperate Javascript file
<div> Time :<span id ="timer"></span></div>
<script type="text/javascript">
var timeoutHandle;
function countdown(minutes, seconds) {
function tick() {
var counter = document.getElementById("timer");
counter.innerHTML =
minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
seconds--;
if (seconds >= 0) {
timeoutHandle = setTimeout(tick, 1000);
} else {
if (minutes >= 1) {
// countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst
setTimeout(function () {
countdown(minutes - 1, 59);
}, 1000);
}
}
if (seconds==0 && minutes ==0){
alert("Game over");
reset();
}
}
tick();
}
countdown(1, 00);
</script>
this is the code used inside HTML. but when i tried using it in the external Js file, it is not working.
<script src="game.js"></script>
the above is the external Js file. Help me out with this problem