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

Tell us what’s happening:

They asked to create a nextSongExists constant that checks if a next song exists by using: userData?.songs[currentSongIndex + 1] !== undefined, but I have tried several ways and still don’t understand what is wrong :') Please help ;;;;

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

audio.addEventListener("ended", () => {
  const currentSongIndex = getCurrentSongIndex();
  const nextSongExists = () => userData.songs[currentSongIndex + 1] !== undefined;
});

Challenge Information:

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

Your code:

audio.addEventListener("ended", () => {
  const currentSongIndex = getCurrentSongIndex();
  const nextSongExists = () => userData.songs[currentSongIndex + 1] !== undefined;
});

Look carefully at userData in both and see if you can spot what you are missing in your code?

I did add a ? mark to it and the code still didn’t work

Please show me the code and the error message

The code:
audio.addEventListener(“ended”, () => {
const currentSongIndex = getCurrentSongIndex();
const nextSongExists = () => userData?.songs[currentSongIndex + 1] !== undefined;
});

The error message: You should check if a next song exists with userData?.songs[currentSongIndex + 1] !== undefined and set it to a nextSongExists constant.

1 Like

You have created a function nextSongExists not a constant

1 Like

Thank you! I got it.