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 JavaScript Array Iteration Methods Array Manipulation Practice map()

Nir Tal
Nir Tal
25,921 Points

why this code is not the right answer??

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; let abbreviatedDays = daysOfWeek.map(daysOfWeek => daysOfWeek.substring(0, 3)); console.log(abbreviatedDays);

the result is like the assignment but i don't pass

abbreviatedDays = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays = daysOfWeek.map(daysOfWeek => daysOfWeek.substring(0, 3));

// abbreviatedDays should be: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
// Write your code below

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! Your code should only be below the comments. This means that the original line with let abbreviatedDays should not be altered. Instead, include your map to change the value of the already declared variable below the comments. Often in these challenges, if they say to write your code below they mean it. Any alteration to the already existing code above will cause the challenge to fail.

Instead, below the comments I would expect to see something like:

abbreviatedDays = //your map here

Hope this helps! :sparkles:

Ignazio Calo
Ignazio Calo
Courses Plus Student 1,819 Points

I suppose is just a small mistake with the validator. Your code is correct but to pass the exercise you need to keep the variable declaration like it is at the beginning of the exescise

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays;
abbreviatedDays = daysOfWeek.map(daysOfWeek => daysOfWeek.substring(0, 3));