Match All Numbers

Tell us what’s happening:
This code gives the correct result…
but the test case are not passing

Your code so far

let numString = "Catch 22";
let numRegex = /\d+/g;
let res = numString.match(numRegex);
let count=0
for(let i=0;i<res.length;i++){
    let a=res[i].toString().length;
    count =count+a;
let result = count;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36.

Link to the challenge:

You might want to re-examine what .match() actually does.

Does it return an array or does it return a string? That is where your problem is.

Plus you may want to read the directions more closely. What you’re returning is not what they want.

In your defense though., this problem should probably ask for a single array with each matched number stored as an index.

1 Like

Thanks man… :slightly_smiling_face:
I was counting no. of digits.
where the question simply asks for digits.