I have fixed your problem, create a new html file and type this :
<!doctype html>
<HTML>
<BODY>
<SCRIPT>
(function(){
var numbers = function (iLoveThree) {
var threes =[];
for (i = 0; i < iLoveThree.length; i++) {
if (iLoveThree[i] % 3 === 0){
threes.push(iLoveThree[i]);
}
}
return threes;
}
alert(numbers([1, 2, 3, 4, 5, 6]));
})();
</SCRIPT>
</BODY>
</HTML>
Hope it helps :)
Explaination :
- You need to include function parameter, this parameter will be accessed inside the function (the parameter is named iLoveThree)
- You were using numbers variable, but this variable had not been declared before, and I fixed this by changing from numbers to iLoveThree
- You missed several ; (semicolon), it's simple but will cause you a lot of trouble
PS : Thanks to RobG for reminding me about giving explaination.
numbersas a function and treating it like an array inside that function.for (i = 0; i < iLoveThree.length; i++)instead ofnumbers.length?. Just guessing because of theif (iLoveThree[i] % 3 === 0)itonumbers.length, yet you are looking in the arrayiLoveThree, notnumbers'.