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

Bug?

My solution returns the correct output, but it fails me and tells me forEach was not used! What's up with that?

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

Object.keys(days).forEach(key => dayAbbreviations.push(days[key].slice(0,2)));

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

Hi Eric,

I imagine the test logic is looking for days.forEach() and other approaches at solving it throw it off.

If you alter your answer to omit Object.keys() you should be able to move on:

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

I get your same error if I swap out the variable:

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