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

J Smillie
PLUS
J Smillie
Courses Plus Student 40,123 Points

I'm sorry it's probably something stupid but why isn't this code passing?

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's what I have:

var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];

print( months.join(', ') );

console.log(months.pop());

7 Answers

That print() function isn't necessary. For that line, you should instead be assigning months.join(', ') to a variable name.

In the console.log() you don't need to use .pop(). You're not popping them off one at a time. When you used the .join() function, you get a string in return which is all of the months, separated by comma and space. Basically you just console.log() the variable you made earlier. Your code should look like this:

var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];

var string = months.join(', ');

console.log(string);

i just put

console.log(months.join(', '));

and it worked. Is that wrong?

I first had in print(months.join(', '));

console.log(months);

and kept saying I wasn't passing, but yours worked and I think it still counts! added space and logged to console.

You don't need print in there. Print() prints the contents of the current window.

You don't need pop either. That is taking the last element out of the array.

As your code is written, it tries to print the curent window, then only logs "December", and your array would now be months = ['January','February','March','April','May','June','July','August','September','October','November'];

You'd just need to join the array with each element separated by a comma and a space, set the new string to equal the old array variable, then log it.

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

Edit: If you want to keep the months array in tact, do as above and set the month.join(', ') to a differently named variable and log that variable.

In practice, I would suggest using a different variable name in the months.join() line. This way you can keep the months array untouched for future use. But since this is just a code challenge, it's fine here.

Yep, edited my answer. I read the question as setting the new string as the itself. I don't know why, ha.

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

why wouldn't the below code pass?

var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];

months.join(', ');

console.log(months);

Use this. var string = months.join(', '); and console.log(months);