title: Javascript - setTimeout
body: <p>I am learning Javascript right now. I have a small issue that I can't figure out how to solve it. I would like to clear content of my html page after my function displayed "Hi hi" in web page.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body onload="alertFunc()"&gt;
  
  &lt;script&gt;
  
  function alertFunc() {
    var statement = "Hi hi"
    for (let i = 0; i &lt; statement.length; i++) {
    let c = statement.charAt(i);
  
    setTimeout(function(){
     document.write(c);
  },i * 1000);
  
  }
  
  }
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>