The .forEach() Method

I am currently working on The .forEach() Method Lesson
Link: .forEach() Method

I created a callback function then used the .forEach() method and printed the data to the console like it ask but I’m still getting an error. What did I not follow or rather what did I miss?

Code:

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

// Iterate over fruits below

let item = (column) =>{
  for(let column = 0; column < fruits; column++){
    console.log(item[column]);
  }
}
fruits.forEach(item => console.log(`I want to eat ${item}.`));

This prints:

I want to eat mango.
I want to eat papaya.
I want to eat pineapple.
I want to eat apple.

Error:

In your callback function do you console.log() to print 'I want to eat _____ ? In the blank, you should concatenate or interpolate the element in fruits array?

Thanks for any advice in advance!

P.S. I feel like my brain can’t connect with what the lesson is asking me to do. Even though the result was correct.

-cheers-

Hello! It looks like you’ve go the concept, it’s just that the lesson wanted you to log I want to eat a ___. Notice the a? You missed that out: I want to eat ___.
I hope this helps!

1 Like

@codeneutrino Let me try again! Thanks for such a fast response.

1 Like

@codeneutrino

Your Right, Thank you!


I was missing the (a) in 'I want to eat a ________.

New Code:

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

// Iterate over fruits below

let item = (column) =>{
  for(let column = 0; column < fruits; column++){
    console.log(item[column]);
  }
}
fruits.forEach(item => console.log(`I want to eat a ${item}.`));
1 Like