title: How to add a space at the end of a string in Javascript
body: <p>I am writing a program which creates a slanted d based off of user input. 
  The program asks for the number of rows and produces the output accordingly.
  If the user enters in 5 it should produce an output of:</p>
  
  <pre><code>d
   d
    d
     d
  </code></pre>
  
  <p>My actual output is:</p>
  
  <pre><code>d
  d
  d
  d
  </code></pre>
  
  <p>Here is my Javascript code:</p>
  
  <pre><code>spaceArray = []; 
  space = ' '; 
  spaceMain = ' ';
  
  
  function processingFunction(rows){ //passes the input as variable rows
      var spaceCounter = 0;          
      var counter = 0;               
  
      while (counter&lt;rows){    
          while (spaceCounter&lt;counter){ 
              spaceMain = spaceMain + space;  //adds a space before the d
              spaceCounter++;         
          }
          counter++; 
          spaceCounter=0; 
          spaceArray.push(spaceMain);  //adds spaceMain to the end of spaceArray
          spaceMain = ' '; 
      }
  
      for (i = 0; i&lt;rows; i++){
          d = spaceArray[i]+"d&lt;br&gt;";
          document.getElementById("outputNumber1").innerHTML += d;                                                                                                   
      }
  
  }
  </code></pre>
  
  <p>When I replace the space variable string from ' ' to '-' it seems to work with an output of:</p>
  
  <pre><code>d
  -d
  --d
  ---d
  </code></pre>
  
  <p>I am not sure what I need to change to get the above output but with spaces instead of dashes.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;style&gt;
      body{background-color: green;} 
  
  &lt;/style&gt;
  
  &lt;body&gt;
      &lt;center&gt;&lt;h2&gt;Slanted d&lt;/h2&gt;&lt;/center&gt;
      &lt;h3&gt;Input the number of rows you would like your slanted d to be in the input text box&lt;/h3&gt;
      &lt;input type="text" id="inputNumber"&gt;&lt;/input&gt; 
      &lt;button type="button" onclick="processingFunction(document.getElementById('inputNumber').value)"&gt;Create slanted d&lt;/button&gt; 
      &lt;br&gt;&lt;br&gt;
      &lt;output type="text" id="outputNumber1"&gt;&lt;/output&gt;
  
  &lt;script src="slantedDJS.js"&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>