title: Learning the DOM
body: <p>I'm learning the DOM in JavaScript and I was doing ok but for some reason, my code isn't working and I have no idea why. I wanted to test running a for loop to change the class of all the elements in an unordered list and it worked, kind of. It skips over one for some reason but everything I do confirms that the index and everything are correct. It gets the one before it and the one after but not it for some reason.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
      &lt;title&gt;repl.it&lt;/title&gt;
      &lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id=&quot;page&quot;&gt;
        &lt;h1 id=&quot;header&quot;&gt;List&lt;/h1&gt;
        &lt;h2&gt;Buy Groceries&lt;/h2&gt;
        &lt;ul&gt;
          &lt;li id=&quot;one&quot; class=&quot;hot&quot;&gt;&lt;em&gt;fresh&lt;/em&gt; figs&lt;/li&gt;
          &lt;li id=&quot;two&quot; class=&quot;hot&quot;&gt;pine nuts&lt;/li&gt;
          &lt;li id=&quot;three&quot; class=&quot;hot&quot;&gt;honey&lt;/li&gt;
          &lt;li id=&quot;four&quot; class=&quot;hot&quot;&gt;balsamic vinegar&lt;/li&gt;
        &lt;/ul&gt;
        &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;
      &lt;/div&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <pre class="lang-css prettyprint-override"><code>.hot {
    color: red;
  }
  
  .cold {
    color: blue;
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>let hot = document.getElementsByClassName(&quot;hot&quot;);
  
  for (let i = 0; i &lt;= hot.length; i++) {
    hot[i].className = &quot;cold&quot;;
  };
  
  </code></pre>
  <p>When I run this, every other item in the list turns blue (fresh figs and honey) but the others (pine nuts and balsamic vinegar) don't. I just can't figure out why it's skipping.</p>
  <p>Any help would be greatly appreciated thank you.</p>