I was trying to solve a JavaScript challenge; the question was
“Given is an array of numbers. Return the number of odd numbers.”
I used the for loop of to take out the odd numbers from the array, and then I pushed the odd numbers into a new array, and then returned the length of the new array. Even though the output matches the expected outcome, it says
Uncaught TypeError: numbers is not iterable on line: 4
Any suggest of what the problem might be?
function countOdds(numbers) {
let odd = [];
let num;
for (num of numbers) {
if (num % 2 === 1) {
odd.push(num);
}
}
return odd.length;
}
countOdds();
New contributor
terry ikporo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.