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

Tell us what’s happening:

How do I do this step. I have been stuck here for weeks.

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 - 1 > currentSongIndex) {
      const nextSongExists = true;
    }
    else {
      const nextSongExists = 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/125.0.0.0 Safari/537.36

Challenge Information:

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

Please talk to us about how the instructions or error message is confusing for you. Thanks

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

Your nextSongExists variable contains a function.

It shouldn’t be a function but an expression that evaluates to true or false which gets assigned to the nextSongExists variable.

const hasSpace = queueLength < maxCapacity;

You have three different nextSongExists variables. Inside the function, you are creating two new nextSongExists variables, each scoped to the block {} in which they were declared. They can only be used inside the block they are scoped to.

You can’t reassign a const but even if nextSongExists was reassignable, reassigning the function with a value from its own body is a terrible idea. Most languages likely won’t even allow for that.

function test() {
  test = "test";
}

test();

console.log(test); // "test"
console.log(test()); // test is not a function

Just do this,\

Mod Edit: SOLUTION REMOVED

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.

Got it. I will not post the solution again.:slightly_smiling_face:

1 Like