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;
});