Build a Music Player - Step 27

Tell us what’s happening:

i need help, my mind stopped working here i donno how to pass this step i tried and searched and read many and i tested results in console but i always fail

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 (userData.currentSong !== null) {

    const nextSong = getNextSong().id
    if(nextSong < allSongs.length) {
      
  } 
  // if (userData.currentSong === allSongs.length - 1) {
  //     userData.currentSong = null;
  //     userData.songCurrentTime = 0;
  //     pauseSong()

  //   }

  }

}
console.log(playSong(4))   
// console.log(audio.title)
console.log(getNextSong()) 
nextButton.addEventListener('click', playNextSong())
// playNextSong()  

// User Editable Region

Your browser information:

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

Challenge Information:

Build a Music Player - Step 27

I guess you are trying to check if the current song is the last one in the playlist?

why don’t you check what getNextSong does if there isn’t a next song?

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

  }
  if(userData.currentSong != null && getNextSong() != null) {
    playSong(getNextSong().id)
  }

  if(userData.currentSong.id == allSongs.length - 1) {
    userData.currentSong = null;
    userData.songCurrentTime = 0
pauseSong() 
  }

}

console.log(userData.songs[0].id)

pauseSong() 

here are my updated code
i execute depend on what failing tests i get on the screen
i passed it one by one till the last one
i think i made what it required but i can’t pass still

and here are my failing test message

// running tests 5. When the

currentSong

of

userData

is equal to

null

, your

playNextSong

function should still call the

playSong

function with the

id

of the first song in the

userData.songs

array as an argument. // tests completed

now i done it i get it , when i nest the last conditions within the first if statement on it’s else choice i passed it.

what a logic i found in the code after i pass the step, i find treasures :slight_smile:
i hope i act like that in the future :slight_smile: