title: Js How to got the sum of numbers from a string?
body: <p>I'm new to coding and have been given this question;</p>
  
  <p>Create a function that takes a string with a jumble of letters and numbers. It should add together all the numbers that appear in the string and return the total.</p>
  
  <pre><code>   E.g. 'foo5bar6cat1' =&gt; 12
     'foo99cat' =&gt; 18
  </code></pre>
  
  <p>Tip: For this one, it might be useful to know that the value <code>NaN</code> in JavaScript behaves oddly. For example, if you do <code>typeof NaN</code> it tells you it's a <code>"number"</code>. Odd, eh?</p>
  
  <p>The code that I have written is this;</p>
  
  <pre><code>function sumDigitsFromString(str) {
  let nums = []
  let sum = 0
  
  for (let i = 0; i &lt; str.length; i++) {
  if (typeOf (arr[i]) === "number") {
   nums.push(str[i])
      }
  }
   for (let i = 0; i &lt; nums.length; i++){
  sum.push(nums[i] + sum)
     }
  return sum
  }
  </code></pre>
  
  <p>The test that my code is being run against is this;</p>
  
  <pre><code>describe("sumDigitsFromString", () =&gt; {
     it("picks out a digit from a string and returns", () =&gt; {
  expect(sumDigitsFromString("foo5foo")).to.equal(5);
     });
       it("sums multiple digits from a string", () =&gt; {
  expect(sumDigitsFromString("5foo5foo")).to.equal(10);
      });
  it("returns a seum of several digits in a string", () =&gt; {
           expect(sumDigitsFromString("hello1world5this3is2a2string")).to.equal(13).;
     });
  });
  </code></pre>
  
  <p>Dose anyone have any suggestion of how to fix my code?</p>