mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-12 07:02:42 -04:00
fix(curriculum): tests passing with seed code in Role playing game (#55580)
This commit is contained in:
@@ -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*>.*<\/head\s*>.*<body\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, /<html[^>]*>.*<head\s*>.*<\/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, /<html[^>]*>.*<body\s*>.*<\/body\s*>.*<\/html\s*>/s);
|
||||
```
|
||||
|
||||
Your code should have a `meta` element.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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--
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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--
|
||||
|
||||
@@ -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]`.
|
||||
|
||||
@@ -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--
|
||||
|
||||
@@ -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--
|
||||
|
||||
@@ -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--
|
||||
|
||||
Reference in New Issue
Block a user