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
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.
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.
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.