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

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

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