title: How to calculate how many rows and columns are needed
body: <p>I want to produce a table with Javascript. I want to give it a number and that's how many cells are created. There are always to be 3 columns however (3 pictures per row)</p>
  
  <p>Could someone help me out with this? I think I need to use the modulus operator but I am unsure of how to use it correctly.</p>
  
  <p>I do not want any extra cells. I can calculate the rows without issue but I don't want extra cells for those rows if that makes sense. So once the cells have been made that row ends even if it's 1 or 2 cells short.</p>
  
  <p>I have this at the moment:</p>
  
  <pre><code>rows = ?? //Not sure how to calculate this
  columns = 3;
  str = "";
  str += '&lt;table border="1" cellspacing="1" cellpadding="5"&gt;';
  
  for(i = 0; i &lt; rows; i++){
     str += '&lt;tr&gt;';
     for (j = 0; j &lt; columns; j++){
        str += '&lt;td&gt;' +  (i + j) + '&lt;/td&gt;';
     }
     str += '&lt;/tr&gt;';
  }
  
  str += '&lt;/table&gt;';
  </code></pre>