Hello, I’m studying JS and there’s a mini-activity I needed to do. It’s using .forEach(). Now I’ve gotten the activity however, it printed
I want to eat a mango
I want to eat a apple
…
I just want to add a condition that would change the articles (a /an) so I made this code. The first line is printing correctly but the succeeding lines are not. I would greatly appreciate it if someone could point me to where the errors are in my code. Thank you!
const fruits = [“Mango”, “papaya”, “pineapple”, “apple”];
// Iterate over fruits below
eatFruits = (fruits) => {
fruits.toLowerCase
fruits.forEach
const vowels = [‘a’,‘e’,‘i’,‘o’, ‘u’]
const firstLetter = fruits.charAt(0);
for (let i = 0; i<vowels.length; i++)
if (firstLetter === vowels[i]) {
console.log('I want to eat an '+ fruits)
} else {
console.log('I want to eat a '+ fruits)
}
}
eatFruits(“apple”);
// prints
I want to eat an apple
I want to eat a apple
I want to eat a apple
I want to eat a apple
I want to eat a apple