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

Tell us what’s happening:

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.

i am having problem with understanding the logic here.

Your code so far

audio.addEventListener("ended", () => {
  const currentSongIndex=getCurrentSongIndex();
  const nextSongExists= userData.songs.length === currentSongIndex ;
  if(userData.songs.length[-1]> currentSongIndex){
    return nextSongExists;;
  }```

});


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.

```text
audio.addEventListener("ended", () => {
  const currentSongIndex=getCurrentSongIndex();
  const nextSongExists= userData.songs.length === currentSongIndex ;
  if(userData.songs.length[-1]> currentSongIndex){
    return nextSongExists;;
  }

});

Your browser information:

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

Challenge Information:

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

  • wrong syntax “userData.songs.length[-1]”, songs data exists on “userData.songs”
  • wrong logic, consider using correct “if statement logic” in there instead

happy coding :slight_smile:

I have rethought and still get stuck Here.Any Guide?

  const currentSongIndex=getCurrentSongIndex();
  const nextSongExists= userData?.songs.length === currentSongIndex;
  if((userData.songs.length - 1)> currentSongIndex){
    return nextSongExists;
  }

});```

Hi @Coder_2024_Eng

Instead of an if statement …

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

Happy coding

Could you explain the error in the if statement Kindly?I Still can’t figure out the boolean part without the if statement.Or maybe a ternary operator still does not work.

nextSongExists= userData?.songs.length === currentSongIndex?true:false

whats your attempted code until now?

1 Like

1st - You need to create the constant nextSongExists , so you need to use:
const nextSongExists =

2nd - You need this constant to either be true or false based on the result of comparing two items. This can be accomplished by simply entering the comparison into the constant, because if you use an operand to compare two strings it will return a boolean value:
const nextSongExists = (userData.songs.length - 1) > currentSongIndex

This will set the constant nextSongExists to either true or false, based on the boolean result of the comparison, which is what you are wanting to accomplish.

I also was having trouble with this one, until I broke it down. Once I established point #1, I was able to figure out point #2 relatively quickly.

6 Likes

I’ve been stuck on this same step for the past few days! I finally figured it out by finding it in some videos and having to connect multiple things.

1 Like

Here is the code I used

REDACTED

This code worked for me to get past step 90!

You really have played a big part in the logic.I cant thank you enough.

I managed to solve it. Thanks alot I was stuck for days.

hey @kagesite

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You will use just 2 lines below the code that already is there,

you dont need the if and else below

need
only the comparative that the exercise asks you to do in the second line

1 Like