title: swap 2 columns in a html table using a javascript function
body: <p>I need to write a Javascript function to swap the second column with the third column, we will open the console and write your function then call it to test.</p>
  <p><a href="https://i.stack.imgur.com/QzoMD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QzoMD.png" alt="Third column (a3-b3-c3) needs to take place of (a2-b2-c2) after calling the function" /></a></p>
  <p>index.html</p>
  <pre><code>    &lt;table style=&quot;margin:auto;&quot; id=&quot;tabel1&quot; class=&quot;mytabel&quot; width=&quot;300&quot; height=&quot;400&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;
          border=&quot;1&quot;&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt; A1 &lt;/td&gt;
                  &lt;td&gt; A2 &lt;/td&gt;
                  &lt;td&gt; A3 &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt; B1 &lt;/td&gt;
                  &lt;td&gt; B2 &lt;/td&gt;
                  &lt;td&gt; B3 &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt; C1 &lt;/td&gt;
                  &lt;td&gt; C2 &lt;/td&gt;
                  &lt;td&gt; C3 &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>
  <p>script.js ( so far )</p>
  <pre><code>function swap(){
      //Write your code here
  
      var tRows = document.getElementById('tabel1').children[0].children;
  
      var column2 = [];
      var column3 = [];
  
  
      for(var i = 0; i &lt; tRows.length; i++) {
          column2[i] = tRows[i].children[1];
          column3[i] = tRows[i].children[2];
      }
  
      console.log(&quot;cell2 &quot; , column2);
      console.log(&quot;cell3 &quot; , column3);
  
  }
  
  swap();
  
  </code></pre>