mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-13 13:00:15 -04:00
fix(curriculum): require at least one space in "else if" (#53016)
This commit is contained in:
@@ -24,19 +24,19 @@ At the end of your `if` statement, add an `else if` statement to check if `monst
|
||||
You should have an `else if` statement.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /else if/);
|
||||
assert.match(attack.toString(), /else\s+if/);
|
||||
```
|
||||
|
||||
Your `else if` statement should check if `monsterHealth` is less than or equal to `0`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /else\s*if\s*\(\s*monsterHealth\s*<=\s*0\s*\)/);
|
||||
assert.match(attack.toString(), /else\s+if\s*\(\s*monsterHealth\s*<=\s*0\s*\)/);
|
||||
```
|
||||
|
||||
Your `else if` statement should call the `defeatMonster` function.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /else\s*if\s*\(\s*monsterHealth\s*<=\s*0\s*\)\s*(\{\s*)?defeatMonster(\s*\})?/);
|
||||
assert.match(attack.toString(), /else\s+if\s*\(\s*monsterHealth\s*<=\s*0\s*\)\s*(\{\s*)?defeatMonster(\s*\})?/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -16,7 +16,7 @@ Inside the `else if` statement, assign the number -5 to the player's x velocity.
|
||||
You should add an `else if` statement to your `animate` function.
|
||||
|
||||
```js
|
||||
assert.match(animate.toString(), /else if/);
|
||||
assert.match(animate.toString(), /else\s+if/);
|
||||
```
|
||||
|
||||
You should check if the left key was pressed and if the player's `x` position is greater than 100.
|
||||
|
||||
@@ -25,7 +25,7 @@ assert.match(code, /if\s*\(\s*keys\.rightKey\.pressed\s*&&\s*isCheckpointCollisi
|
||||
You should add a `forEach` loop that iterates through the `platforms` array.
|
||||
|
||||
```js
|
||||
assert.match(code, /else\sif\s*\(.*\)\s*{\s*platforms\.forEach\(\s*\(platform\)\s*=>\s*{\s*(.*?)\s*}\s*\);?/);
|
||||
assert.match(code, /else\s+if\s*\(.*\)\s*{\s*platforms\.forEach\(\s*\(platform\)\s*=>\s*{\s*(.*?)\s*}\s*\);?/);
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ Congratulations! You have completed the platformer game project!
|
||||
You should add an `else if` clause to check is the player's `x` position is greater than or equal to the checkpoint's `x` position and less than or equal to the checkpoint's `x` position plus `40`.
|
||||
|
||||
```js
|
||||
assert.match(code, /if\s*\(\s*index\s*===\s*checkpoints\.length\s*-\s*1\s*\)\s*\{\s*isCheckpointCollisionDetectionActive\s*=\s*false;?\s*showCheckpointScreen\(("|'|`)You reached the final checkpoint!\1\);?\s*movePlayer\(\s*\1ArrowRight\1,\s*0,\s*false\);?\s*\}\s*else\s*if\s*\(\s*player\.position\.x\s*>=\s*checkpoint\.position\.x\s*&&\s*player\.position\.x\s*<=\s*checkpoint\.position\.x\s\+\s*40\s*\)\s*\{\s*/)
|
||||
assert.match(code, /if\s*\(\s*index\s*===\s*checkpoints\.length\s*-\s*1\s*\)\s*\{\s*isCheckpointCollisionDetectionActive\s*=\s*false;?\s*showCheckpointScreen\(("|'|`)You reached the final checkpoint!\1\);?\s*movePlayer\(\s*\1ArrowRight\1,\s*0,\s*false\);?\s*\}\s*else\s+if\s*\(\s*player\.position\.x\s*>=\s*checkpoint\.position\.x\s*&&\s*player\.position\.x\s*<=\s*checkpoint\.position\.x\s\+\s*40\s*\)\s*\{\s*/)
|
||||
```
|
||||
|
||||
You should call the `showCheckpointScreen` function and pass in "You reached a checkpoint!" as an argument.
|
||||
|
||||
```js
|
||||
assert.match(code, /if\s*\(\s*index\s*===\s*checkpoints\.length\s*-\s*1\s*\)\s*\{\s*isCheckpointCollisionDetectionActive\s*=\s*false;?\s*showCheckpointScreen\(("|'|`)You reached the final checkpoint!\1\);?\s*movePlayer\(\s*\1ArrowRight\1,\s*0,\s*false\);?\s*\}\s*else\s*if\s*\(\s*player\.position\.x\s*>=\s*checkpoint\.position\.x\s*&&\s*player\.position\.x\s*<=\s*checkpoint\.position\.x\s\+\s*40\s*\)\s*\{\s*showCheckpointScreen\(\1You\s+reached\s+a\s*checkpoint!\1\);?\s*\};?/)
|
||||
assert.match(code, /if\s*\(\s*index\s*===\s*checkpoints\.length\s*-\s*1\s*\)\s*\{\s*isCheckpointCollisionDetectionActive\s*=\s*false;?\s*showCheckpointScreen\(("|'|`)You reached the final checkpoint!\1\);?\s*movePlayer\(\s*\1ArrowRight\1,\s*0,\s*false\);?\s*\}\s*else\s+if\s*\(\s*player\.position\.x\s*>=\s*checkpoint\.position\.x\s*&&\s*player\.position\.x\s*<=\s*checkpoint\.position\.x\s\+\s*40\s*\)\s*\{\s*showCheckpointScreen\(\1You\s+reached\s+a\s*checkpoint!\1\);?\s*\};?/)
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
Reference in New Issue
Block a user