Do you need to write out the document or can you display the text in some element like a div
?
If so then you can try something similar to what 'chopper' suggested:
Assuming you have a div
in your page with the id "myDiv"
<div id="myDiv"></div>
Then use this to write out your text:
var myDiv = document.getElementById("myDiv");
setInterval(function () {
if(total == randnum) {
myDiv.innerHTML = "Correct";
} else {
myDiv.innerHTML = "Incorrect";
}
}, 5000);