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

Still stuck on this Using Array Methods Challenge

Here is the question: Use the array method that combines all of the items in an array into a single string. In the final string, the array items should be separated by a comma AND a space. Finally, log the final string value to the console.

Here is the answer I got: var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; months = months.join(', '); console.log(months);

This is the error message I keep getting: There was an error with your code: TypeError: 'undefined' is not a function (evaluating 'months.join(", ")')

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing really well, but you're writing over the original array and clearly the challenge doesn't want you to do this. So you have two options here. Doing it the way you're doing it now but using a different variable name like this:

var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; 
monthString = months.join(', '); 
console.log(monthString);

Or you could do it directly and skip the middle man, like so:

var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; 
console.log(months.join(', '));

Hope this helps! :sparkles:

Thank you so much! that helped a lot!