2.7 | .forEach()


My code

let fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below
fruits.forEach(function(fruit) {
	console.log('I want to eat a ' + fruit);

The console isn’t raising any errors, so I don’t understand why I’m not passing the first objective which is:

  1. Iterate over the fruits array to log I want to eat a plus the name of each fruit to the console. For example, I want to eat a mango.
    Use function(parameter) syntax for this step (not arrow function => syntax).

Can someone explain what I’m doing wrong?


Please remember to include a link when posting questions about exercises. Thanks.

Your code looks fine. Have your tried with a template literal?

console.log(`I want to eat a ${fruit}.`)

Also, is there an expected full stop, perhaps?


Tried a template literal, didn’t work, and there isn’t an expected full stop


Link to exercise, please?




Maybe try the arrow function syntax from step 2 and see if the problem goes away.

My lesson is already done so I can’t tell what will or will not pass the SCT. Here is what I had…

fruits.forEach(fruit => console.log(`I want to eat a ${fruit}`));


Extra Study

Playing with the code after completing a lesson is a nice segue and breather, and helps us to absorb the new information enough to get comfortable with it.

Here is a little grammar checker (run in the lesson editor)…

fruits.forEach(fruit => console.log(`I want to eat \
${'aeiou'.indexOf(fruit[0].toLowerCase()) < 0 ? 'a' : 'an'} ${fruit}.`));
I want to eat a mango.
I want to eat a papaya.
I want to eat a pineapple.
I want to eat an apple.


Ok thanks for your help


Did you make it through the lesson okay?


I’m facing the same issue. i also tried your instructions but it’s still not working


Any help would be highly appreciated