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

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,553 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,553 Points

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

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