title: Javascript string formatting - replace in string saved in a variable
body: <p>Task is simple write numbers from 1 to 99 and replace all numbers where: <code>num (mod 3) =0</code> with each <code>num (mod 5) =0 -&gt; mat</code>, <code>num ( mod 3=0 &amp;&amp; mod 5=0 )</code> with each mat, all others remains the same. That is easy but the formatting is horrible so I want to do this: insert a space between every number and place every "special" word (dividable by 3,5 or both) on a separate line. I know I have to use <code>string.prototype.format</code> but how exactly? here is my current code:    </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;p&gt;Click the button to join two strings into one new string.&lt;/p&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  &lt;script&gt;
  
  
  function myFunction() {
       var text = []; 
        var res = " ";   
  
       for (i=1; i&lt;100; i++){
     if (i%3 == 0 &amp;&amp; i%5 == 0){
          text[i]= "SachMat ";
                  }
         else if (i%3 == 0){
          text[i]= 'sach ';
                  }
          else if (i%5 == 0){
          text[i]= 'mat ';
                  }
  
          else {
          text[i]= i;                
                  }       
        var res = res.concat(text[i]);
         }
  
  
   document.getElementById("demo").innerHTML = res;
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>