diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player/655b49333d9f265bc1512152.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player/655b49333d9f265bc1512152.md index 28429fe53e7..233cca55f6c 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player/655b49333d9f265bc1512152.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player/655b49333d9f265bc1512152.md @@ -7,11 +7,11 @@ dashedName: step-87 # --description-- -Notice that the album art in the HTML and songs in the `allSongs` array have changed. We've swapped out the original songs for shorter ones that you can use to test your app in the upcoming steps. +Notice that the album art in the HTML and songs in the `userData.songs` array have changed. We've swapped out the original songs for shorter ones that you can use to test your app in the upcoming steps. 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 checks if a next song exists. +After that, create a `nextSongExists` constant that contains the boolean value `true` or `false` depending on if the next song exists. # --hints-- @@ -27,10 +27,15 @@ You should create a `currentSongIndex` constant and set it to the calling of the assert.match(code, /audio\.addEventListener\(\s*('|")ended\1,\s*\(\s*\)\s*=>\s*\{\s*const\s+currentSongIndex\s*=\s*getCurrentSongIndex\(\s*\);?\s*.*\s*\}\s*\);?/) ``` -You should check if a next song exists with `userData?.songs[currentSongIndex + 1] !== undefined` and set it to a `nextSongExists` constant. +You should check if a next song exists comparing `userData.songs.length` and `currentSongIndex` and set it to a `nextSongExists` constant. If the last index of the songs array (`userData.songs.length - 1`) is bigger than the currentSongIndex that means there is a next song. ```js -assert.match(code, /const\s+nextSongExists\s*=\s*userData\?\.songs\s*\[\s*currentSongIndex\s*\+\s*1\s*\]\s*!==\s*undefined;?/) +const secondPart = code.split(`audio.addEventListener("ended", () => {`)[1]; +const middlePart = secondPart.split("});")[0] +const codeOutputFirstTest = eval(middlePart + "\nnextSongExists;"); +assert.strictEqual(codeOutputFirstTest, true); +const codeOutputSecondTest = eval(`\nfunction getCurrentSongIndex() { return 100; };\n` + middlePart + "\nnextSongExists;") +assert.strictEqual(codeOutputSecondTest, false); ``` # --seed--