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 trialZach Freitag
20,341 PointsUsing forEach, copy only the first 2 characters of each string in the days array and store the abbreviations in the dayA
Error: dayAbbreviation.push is not a function
This code is not working and this is what was shown in the video. If this code looks good but the system is faulty, ok.
Points go to the best answer.
Cheers!
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 dayAbbreviation = day.slice(0, 2);
dayAbbreviation.push(dayAbbreviation);
});
2 Answers
Ashlee Crusco
9,936 PointsIt looks like your code is just missing the s in dayAbbreviations, your const is dayAbbreviation and the array is dayAbbreviations, hope that helps!
days.forEach(day => {
const dayAbbreviation = day.slice(0, 2);
dayAbbreviations.push(dayAbbreviation);
});
Henry Blandon
Full Stack JavaScript Techdegree Graduate 21,521 PointsHere is another way.
days.forEach(day=> dayAbbreviations.push(day.substring(0,2)))
Zach Freitag
20,341 PointsZach Freitag
20,341 PointsThanks Ashlee! Works like a charm. It's always the small stuff :)