From 4ff1136286cee38bc3f098b85be2d8aa07de273b Mon Sep 17 00:00:00 2001 From: "Krzysztof G." <60067306+gikf@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:36:38 +0100 Subject: [PATCH] fix(curriculum): tests passing with seed code in Role playing game (#55580) --- .../5d5a813321b9e3db6c106a46.md | 6 +++--- .../62a1166ed9a56d439c0770e7.md | 2 +- .../62a3bec30ea7f941412512dc.md | 12 ++++++------ .../62a7bf06d2ad9d1c5024e833.md | 6 +++--- .../62a8b711ab7a12161c7d9b67.md | 2 +- .../62a8cbd1e3595431d5a2b3f1.md | 7 +++++-- .../62a8e49f4df7af5ae2d7a616.md | 2 +- .../62aa2943669c9d5026af6985.md | 6 ++++-- .../62aa2aec2f09d454253aad6c.md | 11 ++++++----- .../62fc20387ef88d1d1998aac5.md | 4 ++-- 10 files changed, 32 insertions(+), 26 deletions(-) diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/5d5a813321b9e3db6c106a46.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/5d5a813321b9e3db6c106a46.md index d3cbfd193a6..3991528fe38 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/5d5a813321b9e3db6c106a46.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/5d5a813321b9e3db6c106a46.md @@ -87,19 +87,19 @@ assert(code.match(/<\/body\s*>/i)); The `head` and `body` elements should be siblings. ```js -assert(document.querySelector('head')?.nextElementSibling?.localName === 'body'); +assert.match(code, /.*<\/head\s*>.*.*<\/body\s*>/s) ``` The `head` element should be within the `html` element. ```js -assert([...document.querySelector('html')?.children].some(x => x?.localName === 'head')); +assert.match(code, /]*>.*.*<\/head\s*>.*<\/html\s*>/s); ``` The `body` element should be within the `html` element. ```js -assert([...document.querySelector('html')?.children].some(x => x?.localName === 'body')); +assert.match(code, /]*>.*.*<\/body\s*>.*<\/html\s*>/s); ``` Your code should have a `meta` element. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a1166ed9a56d439c0770e7.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a1166ed9a56d439c0770e7.md index 0eac43fb139..73da3c508bf 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a1166ed9a56d439c0770e7.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a1166ed9a56d439c0770e7.md @@ -21,7 +21,7 @@ assert.equal(spans?.length, 3); You should give the new three `span` elements a class of `stat`. ```js -assert.exists(document.querySelectorAll('#stats > .stat')?.length, 3); +assert.lengthOf(document.querySelectorAll('#stats > .stat'), 3); ``` Your first `.stat` element should have the provided text `XP: 0`. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a3bec30ea7f941412512dc.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a3bec30ea7f941412512dc.md index 01d81e0c3b4..f263896651d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a3bec30ea7f941412512dc.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a3bec30ea7f941412512dc.md @@ -24,7 +24,7 @@ assert.match(code, /const\s+text/); Your `text` variable should have the value of your `#text` element. ```js -assert.deepEqual(text, document.querySelector('#text')); +assert.match(code, /const\s+text\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#text\1\s*\)\s*/); ``` You should declare a `xpText` variable with `const`. @@ -36,7 +36,7 @@ assert.match(code, /const\s+xpText/); Your `xpText` variable should have the value of your `#xpText` element. ```js -assert.deepEqual(xpText, document.querySelector('#xpText')); +assert.match(code, /const\s+xpText\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#xpText\1\s*\)\s*/); ``` You should declare a `healthText` variable with `const`. @@ -48,7 +48,7 @@ assert.match(code, /const\s+healthText/); Your `healthText` variable should have the value of your `#healthText` element. ```js -assert.deepEqual(healthText, document.querySelector('#healthText')); +assert.match(code, /const\s+healthText\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#healthText\1\s*\)\s*/); ``` You should declare a `goldText` variable with `const`. @@ -60,7 +60,7 @@ assert.match(code, /const\s+goldText/); Your `goldText` variable should have the value of your `#goldText` element. ```js -assert.deepEqual(goldText, document.querySelector('#goldText')); +assert.match(code, /const\s+goldText\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#goldText\1\s*\)\s*/); ``` You should declare a `monsterStats` variable with `const`. @@ -72,7 +72,7 @@ assert.match(code, /const\s+monsterStats/); Your `monsterStats` variable should have the value of your `#monsterStats` element. ```js -assert.deepEqual(monsterStats, document.querySelector('#monsterStats')); +assert.match(code, /const\s+monsterStats\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#monsterStats\1\s*\)\s*/); ``` You should declare a `monsterName` variable with `const`. @@ -84,7 +84,7 @@ assert.match(code, /const\s+monsterName/); Your `monsterName` variable should have the value of your `#monsterName` element. ```js -assert.deepEqual(monsterName, document.querySelector('#monsterName')); +assert.match(code, /const\s+monsterName\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#monsterName\1\s*\)\s*/); ``` # --seed-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a7bf06d2ad9d1c5024e833.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a7bf06d2ad9d1c5024e833.md index a5fcd2f1dec..274fb46e4a9 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a7bf06d2ad9d1c5024e833.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a7bf06d2ad9d1c5024e833.md @@ -16,7 +16,7 @@ In your `goStore()` function, update the `onclick` property for each button to r You should use dot notation to access the `onclick` property of `button1`. ```js -assert.match(code, /button1\.onclick/); +assert.match(goStore.toString(), /button1\.onclick/); ``` You should not use `let` or `const` to access the `onclick` property of `button1`. @@ -40,7 +40,7 @@ assert.match(goStore.toString(), /button1\.onclick\s*=\s*buyHealth/); You should use dot notation to access the `onclick` property of `button2`. ```js -assert.match(code, /button2\.onclick/); +assert.match(goStore.toString(), /button2\.onclick/); ``` You should not use `let` or `const` to access the `onclick` property of `button2`. @@ -64,7 +64,7 @@ assert.match(goStore.toString(), /button2\.onclick\s*=\s*buyWeapon/); You should use dot notation to access the `onclick` property of `button3`. ```js -assert.match(code, /button3\.onclick/); +assert.match(goStore.toString(), /button3\.onclick/); ``` You should not use `let` or `const` to access the `onclick` property of `button3`. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8b711ab7a12161c7d9b67.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8b711ab7a12161c7d9b67.md index b54ee029164..d5dfaaa9114 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8b711ab7a12161c7d9b67.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8b711ab7a12161c7d9b67.md @@ -16,7 +16,7 @@ Inside the `update` function, change the value of the `button1.innerText` assign Your `update` function should use bracket notation to get the `"button text"` property of the `location` object passed into the function. ```js -assert.match(update.toString(), /location[('|")button text\1]/); +assert.match(update.toString(), /location\[('|")button text\1\]/); ``` You should assign the value of the `"button text"` property of the `location` object to the `innerText` property of `button1`. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8cbd1e3595431d5a2b3f1.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8cbd1e3595431d5a2b3f1.md index 3d18aae85fe..20ace910819 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8cbd1e3595431d5a2b3f1.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8cbd1e3595431d5a2b3f1.md @@ -32,8 +32,11 @@ assert.match(buyWeapon.toString(), /newWeapon\s*=\s*weapons\s*;/); `newWeapon` should be declared before you modify `text`. ```js -const contents = buyWeapon.toString().split(/\s+/); -assert.isBelow(contents.indexOf('newWeapon'), contents.indexOf('text.innerText')); +const splitBySpaces = buyWeapon.toString().split(/\s+/); +const textLocation = splitBySpaces.indexOf('text.innerText'); +const newWeaponIndex = splitBySpaces.indexOf('newWeapon'); +const newWeaponLocation = newWeaponIndex !== -1 ? newWeaponIndex : textLocation; +assert.isBelow(newWeaponLocation, textLocation); ``` # --seed-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e49f4df7af5ae2d7a616.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e49f4df7af5ae2d7a616.md index 894b419ce25..1236acee2c4 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e49f4df7af5ae2d7a616.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e49f4df7af5ae2d7a616.md @@ -22,7 +22,7 @@ assert.match(attack.toString(), /monsterHealth\s*-=/); You should use bracket notation with `currentWeaponIndex` to access `weapons`. ```js -assert.match(attack.toString(), /weapons\s*\[\s*currentWeaponIndex\s*\]/); +assert.lengthOf(attack.toString().match(/weapons\s*\[\s*currentWeaponIndex\s*\]/g), 2); ``` You should use dot notation to access the `power` property of `weapons[currentWeaponIndex]`. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2943669c9d5026af6985.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2943669c9d5026af6985.md index 39815c5952c..ced57ddfc20 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2943669c9d5026af6985.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2943669c9d5026af6985.md @@ -27,13 +27,15 @@ After your `for` loop, add an `if` statement to check if the `guess` is in the ` Your `pick` function should have an `if` statement. ```js -assert.match(pick.toString(), /if/); +const split = code.split(/text\.innerText\s*\+=\s*numbers/)?.[1]?.split(/\}/)?.[1]; +assert.match(split, /if/); ``` Inside your `if` statement, check if the `guess` is in the numbers array using the `.includes()` method. ```js -assert.match(pick.toString(), /if\s*\(\s*numbers\.includes\(\s*guess\s*\)\s*\)/); +const split = code.split(/text\.innerText\s*\+=\s*numbers/)?.[1]?.split(/\}/)?.[1]; +assert.match(split, /if\s*\(\s*numbers\.includes\(\s*guess\s*\)\s*\)/); ``` # --seed-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2aec2f09d454253aad6c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2aec2f09d454253aad6c.md index bc95960a7b1..1322379065d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2aec2f09d454253aad6c.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62aa2aec2f09d454253aad6c.md @@ -11,11 +11,11 @@ Since you subtracted health from the player, you need to check if the player's ` # --hints-- -Your `pick` function should have a second `if` statement. +Your `pick` function should have `if` statement nested in the `else` body. ```js -const match = pick.toString().match(/if/g); -assert.isAtLeast(match.length, 2); +const elsePart = code.split(/function\s+pick\s*\(\s*guess\s*\)/)?.[1]?.split(/else\s*\{/)?.[1]?.split(/\}/)?.[0]; +assert.match(elsePart, /if/); ``` Your `if` statement should check if the player's `health` is less than or equal to `0`. @@ -24,10 +24,11 @@ Your `if` statement should check if the player's `health` is less than or equal assert.match(pick.toString(), /if\s*\(\s*health\s*<=\s*0\s*\)/); ``` -Your `if` statement should call the `lose` function. +Your `if` statement in the `else` body should call the `lose` function. ```js -assert.match(pick.toString(), /lose\(\s*\)/); +const nestedIf = code.split(/function\s+pick\s*\(\s*guess\s*\)/)?.[1]?.split(/else\s*\{/)?.[1]?.split(/\}/)?.[0]?.split(/if\s*\(\s*health\s*<=\s*0\s*\)\s*\{/)?.[1]; +assert.match(nestedIf, /lose\(\s*\)/); ``` # --seed-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62fc20387ef88d1d1998aac5.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62fc20387ef88d1d1998aac5.md index 52cf362e9fa..b5e453708d7 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62fc20387ef88d1d1998aac5.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62fc20387ef88d1d1998aac5.md @@ -20,7 +20,7 @@ assert.match(code, /const\s+button2/); Your `button2` variable should have the value of your `"#button2"` element. ```js -assert.deepEqual(button2, document.querySelector('#button2')); +assert.match(code, /const\s+button2\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#button2\1\s*\)/); ``` You should declare a `button3` variable with `const`. @@ -32,7 +32,7 @@ assert.match(code, /const\s+button3/); Your `button3` variable should have the value of your `"#button3"` element. ```js -assert.deepEqual(button3, document.querySelector('#button3')); +assert.match(code, /const\s+button3\s*=\s*document\s*\.\s*querySelector\s*\(\s*('|")#button3\1\s*\)/); ``` # --seed--