Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Arrays Loop Through Arrays Array Methods

Are you logging the final string to the console?

Any idea what's bumming?

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

planets.join(', ');


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 );


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!