mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): Step 87 evaluate code instead of using regex (#53475)
This commit is contained in:
+9
-4
@@ -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--
|
||||
|
||||
Reference in New Issue
Block a user