title: I can't create a dynamic navigation menu using pure JavaScript
body: <p>I tried to create a dynamic navigational menu using pure JavaScript but the code doesn't work.</p>
  <p>I created an empty unordered list that will be filled automatically using JavaScript</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Identify container, sections and empty unorder list.
  const menu = document.getElementById("menu");
  const sections = [...document.querySelectorAll("section")]
  
  
  const nav_menu_items = () =&gt; {
    let nav_menu_container = '';
  
    sections.foreach(section =&gt; {
  
      const sectionID = section.id;
      const sectionAtrribute = section.dataset.nav;
      nav_menu_container += `&lt;li&gt; &lt;a class="menu_item_link" href="#${sectionID}"&gt;${sectionAtrribut}&lt;/a&gt;&lt;/li&gt;`
    })
    menu.innerHTML = nav_menu_container;
  }
  nav_menu_items();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;header&gt;
      &lt;nav&gt;
        &lt;ul id="menu"&gt;&lt;/ul&gt;
      &lt;/nav&gt;
    &lt;/header&gt;
    &lt;section id="container" class="container" data-section="big"&gt;
      &lt;div id="section1" class="section" data-nav="section1"&gt;This is section 1 so hello&lt;/div&gt;
      &lt;div id="section2" class="section" data-nav="section2"&gt;This is section 2 so hello&lt;/div&gt;
      &lt;div id="section3" class="section" data-nav="section3"&gt;This is section 3 so hello&lt;/div&gt;
      &lt;div id="section4" class="section" data-nav="section4"&gt;This is section 4 so hello&lt;/div&gt;
    &lt;/section&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>