title: Cannot read property 'undefined' of undefined
body: <p>Having a bit more trouble with Cookies, I did get my site to save cookies (to-do list items) and reload them after the page had been loaded and place them back into the table on screen. </p>
  
  <p>But, when I deleted all the cookies and tried to start fresh I keep getting a console error saying <code>Cannot read property 'undefined' of undefined</code>  Now, if I comment out the below two sections of code, this problem goes away, but the cookie system will fail of course.</p>
  
  <p>This section checks for the number of items that were in the to-do-list last time someone visited, and sets <code>i</code> as that number, so nothing get's deleted.</p>
  
  <pre><code>var listCookies = document.cookie.split(";");
  
  for(var a = 0; a &lt; listCookies.length; a++) {
  
      var listCount = myCookies[i].trim().split("=");
  
      if(listCount[0].indexOf("listCount") === 0) {
          var i = listCount;
      } else {
          var i = 0;
      }
   }
  </code></pre>
  
  <p>This section finds the actual to-do's themselves and places them in the table on screen. </p>
  
  <pre><code>var myCookies = document.cookie.split(";");
  
  for(var b = 0; b &lt; myCookies.length; b++) {
  
      var cookie = myCookies[i].trim().split("=");
  
      if(cookie[0].indexOf("todo-") === 0) {
  
          window.todoTable.insertAdjacentHTML('beforeend', decodeURIComponent(cookie[1]));
      }
  }
  </code></pre>
  
  <p>I understand the issue is that there aren't any cookies saved on someones first visit, but when I tried to add an <code>if (typeof document.cookie === "undefined")</code> statement that didn't seem to do anything. </p>
  
  <p>I'm assuming I need an if statement wrapped around these pieces of code right? To say, if there isn't a cookie, 'skip this bit'. If there is, 'do stuff'.</p>