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;
      }
}
2 Likes

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.

2 Likes

okay, noted. Thank you

1 Like

So, how are you going to learn then? If you dont understand the code, or understand how to get the right code and choose to rely on AI then its going to be harder for you as the challenges get harder. Also, chatGPT is not going to be right everytime and in facts its often very wrong.

3 Likes

hi,

I am facing the same error. please can you help with hint to resolve it.
thanks

In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.