Build a Music Player - Step 41

Tell us what’s happening:

I check below code output by ‘console.log’ and it show me correct title of current song. but I can’t find right solution to pass this step.

userData.songs[getCurrentSongIndex()].title

Your code so far

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

function setPlayerDisplay() {
  if (userData.songs[getCurrentSongIndex()].title) {
  playinSong.textContent = userData.songs[getCurrentSongIndex()].title;
  }
  else {
    playinSong.textContent = "";
  };

   if (userData.songs[getCurrentSongIndex()].artist) {
  songArtist.textContent = userData.songs[getCurrentSongIndex()].artist;
  }
  else {
    songArtist.textContent = "";
  };

}

// 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/138.0.0.0 Safari/537.36

Challenge Information:

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

userData.songs[getCurrentSongIndex()].title

consider what could happen here if getCurrentSongIndex() returns -1

1 Like

Got it!
I edited my code according to your hint and passed this step.
I also combined the two 'if’s into one.
Thanks.

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