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

After calling getCurrentSongIndex and saving it into currentSongIndex, I need to check if there is a next song. To check if there is a new song, I should get the length of the playlist and compare it to the currentSongIndex. To do that, I grabbed the song length in userData and checked if its value was less than currentSong. If it is true, then I set nextSongExist to true, else false. What did I do wrong? Is my logic wrong? Can anyone give me a hint on how I can solve this? Also, is there more than one answer on freecodecamp or only one solution?

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

assigning this already set to true or false, you don’t need the ternary

can you give the link to the step? it is difficult to know what is happening without being able to debug in the editor

I’m not sure if this is what you mean but here is the link.

read again this sentence, does it make sense? can the length (which is the number of songs) be less than the current song?

=) Thanks for helping me with my silly mistake lol.

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