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

Using 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!

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 dayAbbreviation = day.slice(0, 2);
  dayAbbreviation.push(dayAbbreviation);
});

2 Answers

Ashlee Crusco
Ashlee Crusco
9,936 Points

It 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); 
});

Thanks Ashlee! Works like a charm. It's always the small stuff :)