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

Tell us what’s happening:

I am unable to solve this step. To be honest I am unable to understand the step. I would like to know what the step wants me to do, and where am i going wrong. Thanks you again.

Your code so far

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


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.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge Information:

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

Welcome to the forum @Holla

Currently your code is throwing an error in the console.

It looks like the parentheses are incorrect.

Once you clean up the code, the error messages should give you more helpful messages.

Happy coding

i removed parentheses, also it is not about parentheses.
Also i did try to solve this with ternary operator but for some reason that is not correct answer.
My code so far.
To be honest the step does not provide sufficient detail. The step detail :

###Step 87

Notice that the album art in the HTML and songs in the userData.songs array have changed. We’ve swapped out the original songs for shorter ones that you can use to test your app in the upcoming steps.

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.

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

Error Message :

Sorry, your code does not pass. Hang in there.

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.

true and false like that are not doing anything, and you should assign only and expression to nextSongExists, not a function

sorry but i am not able to understand. Can you please elaborate or provide an example. Thank you

an expression, like for example this one checks if a number is bigger than 10

const isNumberBiggerThan10 = number > 10;

you need to do something similar in your code

please check if my code is in the right direction. I added an if block after the expression. Error message is the same as earlier.

audio.addEventListener("ended", () => {
  const currentSongIndex = getCurrentSongIndex()  
  const nextSongExists = userData.songs.length === currentSongIndex;

delete this please

this is checking if the length is equal to the currentSongIndex, if that the case you can’t have a current song as an array never has an item at an index equal to the length, you need to try to check if there is a next song in a different way

We just need to check whether the length of the array is greater than currentSongIndex.

hi @HarsumeetSingh

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.

1 Like

Thank you for helping me out. I cleared this step.
Thanks again.

const nextSongExists = userData.songs.length > currentSongIndex

Thank you po! for guiding me. 
I wanted to suggest if possible po to make the English more simpler po. Thank you!

You could benefit from the English for Developers course.

But if you have specific feedback of English that is too complex please point that out! You can open a GitHub issue or a post here in the forum

In what way please elaborate more on that because am just confuse

it’s not wrong to use the length, but you need to consider a different approach, like what is the last possible index after which there are no more songs?