title: Using a for loop to get the sum of the filtered elements in an array
body: <p>I'm learning by myself and I'm still a beginner in javascript.
  By doing some exercises I came across this one that asks me to get the sum of the elements in an array that are positive and less than 1001. So I wrote this function, but it returns 0, instead of the desired result. I don't know what I'm doing wrong, I'd appreciate some feedback</p>
  <pre><code>function sumSmallNumbers(n) {
    let smallNumbers = [];
    var sum2 = 0;
    for (let i = 0; i &lt; n.length; i++) {
      if (n[i] &gt; 0 &amp;&amp; n[i] &lt; 1001) {
        smallNumbers.push(n[i]);
  
        function sumFiltered(smallNumbers) {
          for (let j = 0; j &lt; smallNumbers.length; j++) {
            let x = smallNumbers[i];
  
            sum2 = sum2 + x;
          }
        }
      }
    }
    return sum2;
  }
  </code></pre>