Why is this code not working? Is there any rule to put a script tag at the end of the body (when I put the script tag at the end of the body, the code works).
I tried putting the script tag in the head, still not working. Shouldn't the script tag work anywhere inside the body?
<html>
<head>
</head>
<body>
<script>
document.getElementById('output').innerHTML += ('starting...');
var myTimer = window.setTimeout(writeEnding,500);
document.getElementById('output').innerHTML += ('continuing...');
function writeEnding(){
document.getElementById('output').innerHTML += ('ending!');
}
</script>
<p id="output"></p>
</body>
</html>