my code is like that..
i m using isNaN()
but problem is still valid
function numberSearch (str) {
let sum = 0;
let strCount = 0;
if(str === "") {
return 0;
};
for(let i = 0 ; i < str.length; i++) {
if (isNaN(Number(str[i]))) {
strCount = strCount + 1 // if it's true, +1
}
sum = sum + Number(str[i])
}
return Math.round(sum/strCount);
}
let output = numberSearch('Hello6 ');
console.log(output); // --> 1
output = numberSearch('Hello6 9World 2,');
console.log(output); // --> 1
How can I count the number and calculate it?
I'm using isNaN()
, but when i using debugger sum is 'NaN'
I cant treat well.. i cant understand well..