It seems that requestAnimationFrame only works after first run of js code is done: https://jsfiddle.net/pn91zmpc/
var n = 0;
function sleep(ms) {
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while (curDate - date < ms);
}
function refresh() {
var body = document.getElementsByTagName("body")[0];
body.textContent = n;
}
n=0;
window.requestAnimationFrame(refresh);
n = n+1;
sleep(2000);
n = n+1;
sleep(2000);
n = n+1;
I expected to see a countdown. Instead, I only see the last result. What do I need to change to see a countdown?