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
ILM
December 18, 2024, 2:32pm
2
booleanmethod9:
"true" : "false"
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
ILM
December 18, 2024, 3:04pm
4
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
:
An array is a single variable used to store elements of different datatypes so that they can be accessed through a single variable. It is an ordered list of values, and each value is referred to as an element, which is specified by an index. Knowing...
ILM
December 19, 2024, 8:36am
7
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?
ILM
December 19, 2024, 11:34am
9
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:
The conditional (ternary) operator is the only JavaScript operator that takes three operands:
a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to...
Something like this?:
audio.addEventListener("ended", () => {
const currentSongIndex = getCurrentSongIndex();
const nextSongExists ? "true" : "false";
});
ILM
December 21, 2024, 7:59pm
13
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
…
ILM
December 21, 2024, 8:11pm
15
it is not valid syntax. const variableName
must always be followed by an assignment operator
what do you want the line to do?
ILM
December 21, 2024, 8:16pm
16
when next week the new curriculum is announced, please try it out
Trying to check if a (nextSongExists
)…
ILM
December 21, 2024, 8:21pm
18
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…
ILM
December 21, 2024, 8:37pm
20
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?