Build a Music Player - Step 27

Tell us what’s happening:

Hi, I’m failing test no.5 which is from the previous step and it should be passing but I’m not sure why it isn’t

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const playNextSong = () => {
  if (userData.currentSong === null) {
    playSong(userData.songs[0].id);
  }
  if (getNextSong() === undefined) {
    userData.currentSong = null;
    userData.songCurrentTime = 0;
    pauseSong();
  }
  else {
    playSong(getNextSong().id)
  }
}


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0

Challenge Information:

Build a Music Player - Step 27
https://www.freecodecamp.org/learn/full-stack-developer/workshop-music-player/step-27

The instructions imply that there should be an else after the if in the seed code. And you might want to consider creating a variable to capture the result of getNextSong() and moving on from there.

I peeked into step 28 to see that a return is added to the first if block, I tried that and I passed, however, would still appreciate if anyone can explain why the return matters in this case

There was no else in that approach, so the return was added to prevent the code below that point from executing.