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 Challenge 2 Solution

Extra parenthesis at the end of the video.

Just wanted to point out that there is an extra parenthesis in the code at the end of the video.

4 Answers

days.forEach(day => dayAbbreviations.push(day.slice(0, 2)));

Where's the extra parenthesis?

There isn't one actually, I was overlooking one of the opening parenthesis. Thanks.

kevinardo
seal-mask
.a{fill-rule:evenodd;}techdegree
kevinardo
Treehouse Project Reviewer

I often get confused and think that there is an extra parenthesis when there are 3 in a row, even if it is correct. Looks a bit funky, but that's the way we roll :)

Michel Ribbens
Michel Ribbens
18,417 Points

agree, I personally like it more to write the code like this instead of putting everything on one line. also, I use more often a bit of extra space between the first and last parenthesis. makes it a bit more readable in my opinion

this was my solution:

days.forEach( day => {
  dayAbbreviations.push( day.substring(0, 2) );
});

console.log(dayAbbreviations);

oh btw for those that are using VS Code as their editor: install the plugin Bracket Pair Colorizer. great plugin that adds extra colors to figures like [], {}, () etc. makes it a lot easier to check and debug your code!

Jay Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Jay Thomas
Full Stack JavaScript Techdegree Student 6,734 Points

I didn't remember about substring or slice. So I used:

days.forEach(day => { dayAbbreviations.push( day.charAt(0) + day.charAt(1)) });