fix(curriculum): Step 87 evaluate code instead of using regex (#53475)

This commit is contained in:
Pedro Ramos
2024-02-05 01:23:10 +06:00
committed by GitHub
parent c21c47a5e1
commit b616afcdb1
@@ -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--