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
Modestas Kiudulas
1,590 PointsWhy wouldnt this JS code be valid?
Hi, I'm currently learning arrays on the beginner JS course. One of the questions states:
"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."
They provide you this code:
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
This was my solution which in my mind seems very reasonable but it doesnt seem to work for some reason:
months = months.join(', '); console.log(months);
Now, after researching, I found out that the answer was to create a new variable instead of reassigning the months.join() to the months variable but my question is why doesn't this work? it seems more efficient than creating an entirely new variable.
Thanks,
2 Answers
Cory Harkins
16,500 PointsIt works, you can test it in the console of your browser; however, you're right, it doesn't work to execute the pass. Some of the challenges are strict with their answers.
I won't even begin to defend it. Nice work though!
Modestas Kiudulas
1,590 PointsThanks for the prompt response.