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 trialMelvin Miller
4,242 PointsMy code won't print to my console
The challenge cleary states, us an array method. Which I did. Also log the final string. Which i did.
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
months.join(', ');
console.log(months);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Tobias Helmrich
31,603 PointsHey Melvin,
the join method returns all the array items separated by the specified separator, however it's not overwriting the existing variable (in this case months), so you're logging the array to the console.
Just save the result of the join method on the months array to a new variable and log it out to the console and you should be good to go! :)
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var finalString = months.join(', ');
console.log(finalString);
or you could also directly log the return value of the join method to the console like so if you prefer:
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
console.log(months.join(', '));
Melvin Miller
4,242 PointsThanks I figured it out already, prior to you answer. Thanks a though!
Here's how I did it. Here's another way var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
months.join(); console.log(months.join(', '));
Tobias Helmrich
31,603 PointsGlad you got it working! :) Yep, perfectly fine as well. But you didn't even have to write the first months.join();
as it won't be evaluated. Also note that if you use the join method without any arguments it will separate all items in the array with a "," but it won't put a space after the comma like the challenge requires. Happy coding!