title: Cannot read property childNodes of null
body: <p>Why do  I get the error cannot read property childNodes of null? This code is obtained from the book SAMS Teach Yourself Javascript in 24 hours.</p>
  
  <pre><code>  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;To-Do List&lt;/title&gt;
      &lt;script&gt;
      var text = "";
      var pElement = document.getElementById("toDoNotes");
      for (var i=0; i &lt; pElement.childNodes.length; i++) {
          if (pElement.childNodes[i].nodeType ==3){
          text += pElement.childNodes[i].nodeValue;
          };
          }
      alert("The paragraph says:\n\n" + text);
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Things To Do&lt;/h1&gt;
      &lt;ol id="toDoList"&gt;
          &lt;li&gt;Mow the lawn&lt;/li&gt;
          &lt;li&gt;Clean the windows&lt;/li&gt;
          &lt;li&gt;Answer your email&lt;/li&gt;
      &lt;/ol&gt;
      &lt;p id="toDoNotes"&gt;Make sure all these are completed by 8pm so you can watch the game on TV!&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>