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 Arrays Loop Through Arrays Array Methods

Are you logging the final string to the console?

Any idea what's bumming?

script.js
const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

planets.join(', ');

console.log(planets);

2 Answers

Hi. In your code, you are still logging the planets array to the console. You did join the array members into a string with the .join() method; however, that doesn't affect the original array. That method will return a new string. So in order to print that to the console you could do either of the following:

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

// Storing the result as a variable to use later
planetsAsString = planets.join(', ');

console.log(planetsAsString );

or

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

// Directly printing the results of planets.join() to the console, without creating a new variable
console.log(planets.join(', '));

I would recommend opening the developer tools in your browser and manually executing every line of code in both of these example (line by line) so that you can see the difference and see how it works. Please let me know if that helps.

sure thks!