As you can see in the code below, I want to run the loop 3 times and in each run write a line to the document. However, when I open the page, the alert message pops up 3 times and only then I see the new words on the page.
Why is it happening? Is there a way to update the document while still in the loop?
I'm guessing it's related to the "window" and "document", but I'm not quite sure how they work... Anyway, thanks in advance!
<!DOCTYPE html>
<html>
<script>
var words = ["please", "print", "me!"]
for (word of words) {
alert("don't mind me!");
document.write(word + "</br>")
}
</script>
</html>