Learn Basic String and Array Methods by Building a Music Player - Step 42

I really don’t understand why the test is not passing. Can someone help me out?

This is the challenge text:

Step 42
To get the index for the current song, you can use the indexOf() method. The indexOf() array method returns the first index at which a given element can be found in the array, or -1 if the element is not present.

const animals = ["dog", "cat", "horse"];
animals.indexOf("cat") // 1
Inside your getCurrentSongIndex function, return userData?.songs.indexOf(). For the indexOf() argument, set it to userData?.currentSong.

And here is what I have

const getCurrentSongIndex = () => (
  userData?.songs.indexOf(userData?.currentSong);
);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0

Challenge Information:

Learn Basic String and Array Methods by Building a Music Player - Step 42

Hey @Mesha8,

Welcome to the community! As the challenge mentions, you should return the index in your function, and as of now the statement is missing.

Just add the return statement at the beginning inside your function and that should fix it.

Unfortunately that still doesn’t work.

What I have now is:

const getCurrentSongIndex = () => (
return  userData?.songs.indexOf(userData?.currentSong);

);

And the console says:

// running tests
SyntaxError: unknown: Unexpected token (134:2)

  132 |
  133 | const getCurrentSongIndex = () => (
> 134 |   return userData?.songs.indexOf(userData?.currentSong);
      |   ^
  135 | );
  136 |
  137 | playButton.addEventListener("click", () => {

yes, written like this the function expects implicit return, without the return keyword, if you want to use explicit return you need to use {} to surround the function body

surrounding the function body gives me a different error.

I guess I am supposed to use implicit return here, but I am again stuck on the first step then.

What I have:

const getCurrentSongIndex = () => (
  userData?.songs.indexOf(userData?.currentSong)
  );

What the console says:

You should return userData?.songs.indexOf() inside your getCurrentSongIndex function. You should pass in userData?.currentSong into the indexOf() method.

try without the round parenthesis around the body of the function, maybe

That was it, thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.