Skip to content

Instantly share code, notes, and snippets.

@scriptnull
Created February 21, 2014 16:11
Show Gist options
  • Save scriptnull/9137105 to your computer and use it in GitHub Desktop.
Save scriptnull/9137105 to your computer and use it in GitHub Desktop.
My approach of writing a js timer !
<html>
<head>
<title>Timer</title>
<script type="text/javascript">
function onloadME (timer) {
window.setInterval(timerfunc,1000);
}
sec = 0 ;
min = 0;
hour = 0;
var timerfunc = function(){
sec++;
timer.innerHTML = hour + " : " + min + " : " + sec ;
if(sec==60)
{
sec=0 ;
min++;
timer.innerHTML = hour + " : " + min + " : " + sec ;
if(min == 60)
{
min=0;
hour++;
timer.innerHTML = hour + " : " + min + " : " + sec ;
}
}
}
</script>
</head>
<body onload="onloadME(timer)">
<p id="timer">Timer Appears Here !</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment