<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<span>10</span>
<script>
(function fn(){
if(--document.querySelector('span').textContent) setTimeout(fn, 1000);
else document.body.style.backgroundColor = "red";
})();
</script>
</body>
</html>