fix(learn): Clarify RPG step 146 example (#53768)

This commit is contained in:
Giuseppe Soriano
2024-02-16 21:57:21 +01:00
committed by GitHub
parent dcccc6749d
commit 3ef8a4bf02

View File

@@ -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.