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

Tell us what’s happening:

I am not sure what i am doing wrong here pls can somone explain. I have also reset the challenge multiple times and it is still not working

Your code so far

audio.addEventListener("ended", () => {
  
});
const playNextSong = () => {
  const currentSongIndex = getCurrentSongIndex();
  const nextSongExists = currentSongIndex < userData.songs.length - 1;

  if (nextSongExists) {
    const nextSong = userData.songs[currentSongIndex + 1];
    playSong(nextSong.id);
  } else {
    console.log("No next song available.");
  }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

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

1 Like

Hello @mbas, from what I read, you were asked to create currentSongIndex and nextSongExists alone and in the audio event listener. These are the only things required to pass this step. The if statement is making your test fail.

I have now removed the if statement but it still does not work

audio.addEventListener("ended", () => {
  
});
const playNextSong = () => {
  const currentSongIndex = getCurrentSongIndex();
  const nextSongExists = currentSongIndex < userData.songs.length - 1;
  }

Hi @mbas !
The instructions is asking you:
Retrieve the current song index by calling the getCurrentSongIndex() function, and save it in a currentSongIndex constant.

After that, create a nextSongExists constant that contains the boolean value true or false depending on if the next song exists.

You need to add the instructed code values within eventListener()s call back function’s body.

Also you need to write the second code line for nextSongExists using ternary operator.
To check if nextSongExists. if it is, add true if not add false.
Reset your challenge step and try again your code within the event listener call back function.