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 trialSeokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsMy 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.
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
231,269 PointsThe 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
Full Stack JavaScript Techdegree Graduate 21,606 PointsSeokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsThank 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.