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

Tell us what’s happening:

Please assist me . The error message says “You should create a currentSongIndex constant and set it to the calling of the getCurrentSongIndex function”

Your code so far

<!-- file: index.html -->

/* file: styles.css */

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

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

  
 

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

Challenge Information:

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

Hello @eletontee!

This step is a bit of a challenge, but you will get there.

The first part of the challenge you have completed by creating the variable currentSongIndex which calls the getCurrentSongIndex function - intuitively the getCurrentSongIndex function will return an integer.

The next part of the challenge is to determine whether a nextSongExists. Yes or no (or true or false) is the answer to this question which means a comparison is necessary.

The easiest way to assign a boolean, in this case, to the nextSongExists, will be to write a conditional or a ternary expression.

Something like:

if (some condition is true) {
  true;
} else {
  false;
}

The code you wrote below is generally going in the correct direction but, it needs to be simpler and written correctly syntactically.

Does this help?

Keep up the good progress!

Happy Coding! :slightly_smiling_face:

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

tried like this but its still not passing. please give me a hint

Have a look at this article: How to Use the Ternary Operator in JavaScript – Explained with Examples

Also, try formatting your code according to standard Guidelines for writing JavaScript code examples. It will help people to help you.

I would format your code (as it is) like this:

audio.addEventListener(“ended”, () => {
     const currentSongIndex = getCurrentSongIndex();
});

const nextSongExists = () => {
      if(userData.songs.length - 1 > currentSongIndex) {
            true;
      }else{
             false;
      }
}
1 Like

The solution can be found here:

You do not create an arrow function for nextSongExists to assign the boolean value to it. You can just use a ternary operator.

I had the same issue, but I got passed with the following code:
SOLUTION REMOVED

hey @bueze5

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

okay, noted. Thank you