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

I think this code should be accepted

Result is right and forEach IS used... :)

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
  .filter(letter => letter !== 'L')
  .forEach(letter => noel.push(letter))

1 Answer

Matthew Long
Matthew Long
28,407 Points

Looks good other than the missing semicolon. However, I think the challenge wants you to focus on .forEach() so try something like:

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

alphabet.forEach(letter => {
  if (letter != "L") {
    noel.push(letter);
  }
});

You could always use the conditional operator if you want to stay clean like you had:

alphabet.forEach(letter => letter != "L" ? noel.push(letter) : null);