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

Daniela Garcia
Daniela Garcia
5,067 Points

Bummer: Are you using the method that joins array elements and returns a new string?

What's my error here?

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

2 Answers

Hi Daniela!

This passes both tasks:

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

// Task 1
const planetStr = planets.join(", ");
console.log(planetStr);

// Task 2
const pos = planets.indexOf('Saturn');
console.log(pos);

This would also work (not using variables):

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

// Task 1
console.log( planets.join(", ") );

// Task 2
console.log( planets.indexOf('Saturn') );

I hope that helps.

Stay safe and happy coding!

Clare Yeadon
Clare Yeadon
5,452 Points

Good morning, My answer for task 2 was the same as your but I copied and pasted your since maybe I was missing a space or something and I am still getting the same "Bummer wrong answer". Any thoughts?

Can I see your whole actual block of code?

Some typos are elusive!?!

Clare Yeadon
Clare Yeadon
5,452 Points

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

console.log(planets.indexOf(Saturn));