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()

stuck on code challenge

I can't seem to figure out how to get my new array formed from map() into the let abbreviatedDays, any suggestions?

app.js
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays;

// abbreviatedDays should be: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
// Write your code below
const abbr = daysOfWeek.map(day => day.substring(0,3));

2 Answers

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

I used slice instead of substring, it works.

I tried, that it still says "you haven't changed the variable value of abbreviatedDays yet."

Valeshan Naidoo How did you get the new array into the let variable abbreviatedDays?

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

So you need to use the variable abbreviatedDays that was supplied,

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays;

// abbreviatedDays should be: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
// Write your code below
abbreviatedDays = daysOfWeek.map(day => day.slice(0,3));
Valeshan Naidoo
Valeshan Naidoo
27,008 Points

In line 2 you can see that let allows us to create an empty variable, we can re-write the variable empty variable to anything we want.