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

pakarang buacharoen
seal-mask
.a{fill-rule:evenodd;}techdegree
pakarang buacharoen
Full Stack JavaScript Techdegree Student 1,897 Points

I think the console.log line was where I went wrong, but I can't seems to figure out how to solve it

Use the array method that combines all of the elements inside the planets array into a single string.

script.js
const planets = ['Earth','Mars','Saturn','Mercury','Jupiter','Venus','Uranus','Neptune'];
planets.join(', ');
console.log(i);

2 Answers

Steven Parker
Steven Parker
231,172 Points

You haven't defined anything named "i". Did you mean to create a new variable by that name on line 2 and assign the joined string to it?

Fayez Mamdoh
Fayez Mamdoh
2,530 Points
const planets = [
  "Earth",
  "Mars",
  "Saturn",
  "Mercury",
  "Jupiter",
  "Venus",
  "Uranus",
  "Neptune",
];
console.log(planets.join(", "));
console.log(planets);
Steven Parker
Steven Parker
231,172 Points

Yes, you can skip creating the variable. But you don't need that last line, logging the original list isn't part of the challenge.