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

Seokhyun Wie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 Points

My answer is right, but it is not accepted as an answer.

const days = [
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
];
let dayAbbreviations = [];

// dayAbbreviations should be: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
// Write your code below
days.forEach(day => {
  const twoChar = `${day[0]}${day[1]}`;
  dayAbbreviations.push(twoChar);
});

console.log(dayAbbreviations);

This prints out ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], but is not accepted as an answer.

app.js
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let dayAbbreviations = [];

// dayAbbreviations should be: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
// Write your code below
days.forEach(day => {
  const twoChar = `${day[0]}${day[1]}`;
  dayAbbreviations.push(twoChar);
});

console.log(dayAbbreviations);

1 Answer

Steven Parker
Steven Parker
229,745 Points

The validation mechanism used here was probably developed prior to ES6. Plus, a template string is a bit fancy (and unnecessarily verbose) for this challenge.

Try just using simple concatenation instead.

Seokhyun Wie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 Points

Thank you for answers always Steven. I was slightly more concentrated on RegEx because I just learned it. However, after I learned about map, reduce etc., now I totally understand why it can be regarded as verbose.