There were a few problems.
You needed to access the number in the array using the numbers[i] index, and not just check the index.
You also need to pass two parameters to the iLoveThree function.
Here is the working code:
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; var threes = []; var iLoveThree = function (numbers, threes) { for (i in numbers) { if (numbers[i] % 3 === 0) { threes.push(numbers[i]); } } return threes; }; console.log(iLoveThree(numbers, threes));
As an additional note, you can simplify your code using the .filter() method.
If the logical num % 3 === 0 true, then the number is not removed from the array.
var numbers = [1,2,3,4,5,6,7,8,9].filter(function (num) { return num % 3 === 0; }); console.log(numbers);
source share