Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Practice forEach in JavaScript Practice forEach forEach Practice - 4

The split method turns a string into an array. In the case of alphabet below, each letter of the string is being turned

Hey! i'm stuck in this exercises and i try a lot of different solutions but i can't find how to remove the letter 'L' in an Array with forEach

Thanks in advance for the help

app.js
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let noel = [];

// noel should be: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
// Write your code below

alphabet.forEach(alphabets => {
  if(alphabets.charAt(0) === 'L') {
    noel.push(alphabet);
  }
});

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Yannis Bouacida ! It seems like you're on the right path but there are two things going wrong here. First, your comparison is incorrect. You are checking to see if the letter is "L". If it is, push it to the noel array. But this is exactly backward. We want to push in everything that is not equal to "L". So where you have === "L" you will need != "L".

Secondly, you chose to name the individual letter alphabets. I might have chosen a different name here to make it more clear that it is an individual letter from the alphabet. But ultimately, the variable name doesn't really matter. Here's the part that does matter though:

You wrote...

noel.push(alphabet);

But you meant to write...

noel.push(alphabets);

Remember, alphabet is the array of letters while alphabets is the individual letter being considered.

Hope this helps! :sparkles:

Thank you very much for the help!