I am trying to run a function for every millisecond. To achieve this, I just preferred the concept setInterval
in javascript. My code is below
HTML:
<div id=test>0.0</div>
Script:
var xVal = 0;
var xElement = null;
xElement = document.getElementById("test");
var Interval = window.setInterval(startWatch, 1);
function startWatch(){
xVal += 1;
xElement.innerHTML = xVal;
}
so the above code is working fine. But while I'm testing the result with a real watch, a real watch needs 1000 milliseconds to complete 1 second, and at the same time it takes more than 1000 milliseconds to complete.
Demo
Can anyone tell me
Are there any errors with my code? If so, tell me how to accurately display milliseconds.?
source
share