I am trying to make a stop watch in js and my code is working correctly until I include Millisecond in my stopwatch.
Here's my code:
index.html
<html>
<head>
<title>My Second Page</title>
<script src="script.js"></script>
</head>
<body>
<input type="button" onclick="gettime()" value="Start Stopwatch"></a>
</body>
</html>
script.js
var ss = 0,
mm = 0,
hh = 0,
ms = 0;
var once = 0;
function gettime() {
if (once == 0) {
document.write('<h1 id="stopwatch"></h1>');
once++;
}
setInterval("msss()", 100);
}
function msss() { // I have defined msss
printtime();
if (ms > 1000) {
sec();
} else {
ms += 100;
}
}
function sec() {
ms = 0;
printtime();
if (ss > 59) {
min();
} else {
ss += 1;
}
}
function min() {
ss = 0;
printtime();
if (mm > 59) {
hr();
} else {
mm += 1;
}
}
function hr() {
mm = 0;
printtime();
hh += 1;
}
function printtime() {
document.getElementById('stopwatch').innerHTML = 'H: ' + hh + 'M: ' + mm + ' S: ' + ss + ' MS: ' + ms;
}
Error Code
ReferenceError: msss is not defined
What am I doing wrong?