Building a Music Player Step 87

The instructions are

Blockquote
Next, you need to check if there is a next song to play. Retrieve the current song index by calling the getCurrentSongIndex() function, and save it in a currentSongIndex constant.
After that, create a nextSongExists constant that contains the boolean value true or false depending on if the next song exists.

my code is

audio.addEventListener("ended", () => {
  const currentSongIndex = getCurrentSongIndex();
 if (currentSongIndex > userData.songs.length-1) {
   let nextSongExists = true;
 } else {
   let nextSongExists = false;
   });
 }

And i’m getting the error message

Blockquote
You should create a currentSongIndex constant and set it to the calling of the getCurrentSongIndex function.

For the life of me I cannot see the error in the code.

Hi @blake833

You have a syntax error in your code, the parentheses are not closed properly, which is why you are not getting the correct error message.

You correctly created the currentSongIndex variable.

Reset the step to restore the original code, then insert just the first variable.
The error message will indicate how to structure the nextSongExists variable.

Happy coding

1 Like

Thank you I totally missed that parenthesis being out of place.

The error code I’m now getting, and was getting sometimes earlier, is " You should not modify the existing ended event listener and its content." But when I move it outside the event listener, I go back to the other error code.

1 Like

After pasting the first variable, just code the second variable.
I think the error message is checking for both variables, so sees just one variable as a modification.

1 Like

Teller, I can’t tell you how much I appreciate your help. I think you might also be overestimating my comprehension here lol. So the two variables would be currentSongIndex, and nextSongExists? I added a line declaring the variable with let, but i’m not sure i understand how it’s checking for both variables, and just seeing one as a modification.

updated code:

Blockquote
audio.addEventListener(“ended”, () => {
const currentSongIndex = getCurrentSongIndex();
let nextSongExists;
if (userData.songs.length - 1 > currentSongIndex) {
let nextSongExists = true;
} else {
let nextSongExists = false;
}
});

Your code is not throwing a syntax error.

Here are the instructions for part 2.

After that, create a nextSongExists constant that contains the boolean value true or false depending on if the next song exists.

Continuing to debug. the console has this message:

You should not modify the existing ended event listener and its content. You should create a currentSongIndex constant and set it to the calling of the getCurrentSongIndex function. You should check if a next song exists comparing userData.songs.length and currentSongIndex and set it to a nextSongExists constant. If the last index of the songs array (userData.songs.length - 1) is bigger than the currentSongIndex that means there is a next song. // tests completed

Both mention constant, so declare the variable nextSongExists using the keyword constant

Looks like the tests are wanting you to check a condition rather than use if / else statements.

1 Like

thank you that’s what i wasn’t seeing :person_facepalming: I passed with that help!

1 Like

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