mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-27 11:01:38 -04:00
fix(learn): Clarify RPG step 146 example (#53768)
This commit is contained in:
@@ -14,13 +14,15 @@ The `ternary operator` is a conditional operator and can be used as a one-line `
|
||||
Here is an example of returning a value using an `if-else` statement and a refactored example using a ternary operator:
|
||||
|
||||
```js
|
||||
if (num > 5) {
|
||||
return 'num is greater than 5';
|
||||
// if-else statement
|
||||
if (score > 0) {
|
||||
return score
|
||||
} else {
|
||||
return 'num is smaller than or equal to 5';
|
||||
return default_score
|
||||
}
|
||||
|
||||
return num > 5 ? 'num is greater than 5' : 'num is smaller than or equal to 5';
|
||||
// ternary operator
|
||||
score > 0 ? score : default_score
|
||||
```
|
||||
|
||||
In `getMonsterAttackValue`, change `return hit` to a ternary operator that returns `hit` if `hit` is greater than `0`, or returns `0` if it is not.
|
||||
|
||||
Reference in New Issue
Block a user