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

Tell us what’s happening:

The question says nothing about userData.songs.length and then it asks for where it is in the feedback prompt? Can someone please explain please?

Your code so far

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

/* file: styles.css */

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

audio.addEventListener("ended", () => {
    const currentSongIndex = getCurrentSongIndex();
    const nextSongExists = "true" : "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/131.0.0.0 Safari/537.36

Challenge Information:

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

this is not valid javascript

you should return a boolean value

if you have an index of an array, how can you check if there is something after that element? there are many ways, you are free to use any way

what are the many ways

1 Like

For example, how do you make sure, when iterating over an array with a for loop, to not go outside the array with the index?

how do you make sure when iterating over an array with a for loop to not do that

Here’s a link to an article about loop:

I’m asking you, so far you would have written many for loops to iterate over an array! try to write one and analyse it
what parts does it have?

Are you talking about the initialization condition and increment?

they are the parts of a loop, yes. in one of those you would write something that make so that the indeces do not go to values that can’t be found in the array

The other answers in the forum seem to have something different

Hi there!

You need to write a ternary condition. Here’s a guide:

Something like this?:

audio.addEventListener("ended", () => {
    const currentSongIndex = getCurrentSongIndex();
    const nextSongExists ? "true" : "false";
});

there is many ways in which you can solve this.
If you remind yourself which condition is used to make sure that the index doesn’t go outside the array, you can use that one.
It’s not the only one.


What do you think this is doing?

its supposed to serve as a high powered if statement if I am not mistaken, for nextSongExists

it is not valid syntax. const variableName must always be followed by an assignment operator

what do you want the line to do?

when next week the new curriculum is announced, please try it out

Trying to check if a (nextSongExists)…

in what way, what part of that line of code is the operator or method that does that specific check?

The condition does not seem to exist. Up to me I’d say ‘if the next song exists’ seems to be the condition…

let’s ignore that line

let’s try to understand how to work out the problem

you have a list of songs, which are in an array
you have the index of the current song
you need to check if there is a next song

let’s do a simple version of the problem:
there is an array of three songs: ["song1", "song2", "song3"]
if the index of the current song is 0, is there a next song?
if the index of the current song is 1, is there a next song?
if the index of the current song is 2, is there a next song?