title: Square each number in an array in javascript
body: <p>I'm trying to square each number in an array and my original code didn't work. I looked up another way to do it, but I'd like to know WHY the original code didn't work.</p>
  
  <p>Original code:</p>
  
  <pre><code>function(arr) {
  
      ret= [];            
  
      for (var i = 0, len = arr.length; i &lt; len; i++) {
          root = Math.sqrt(arr[i]);
          ret.push(root);
      }
  
      return ret;
  }
  </code></pre>
  
  <p>Working Code:</p>
  
  <pre><code>function(arr) {
  
      ret= [];
  
      for (var i = 0, len = arr.length; i &lt; len; i++) {
          ret.push(arr[i] * arr[i]);
      }
  
      return ret;     
  }
  </code></pre>