* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
107 lines
1.8 KiB
Markdown
107 lines
1.8 KiB
Markdown
---
|
|
id: 56533eb9ac21ba0edf2244da
|
|
title: Introducing Else Statements
|
|
challengeType: 1
|
|
videoUrl: 'https://scrimba.com/c/cek4Efq'
|
|
forumTopicId: 18207
|
|
dashedName: introducing-else-statements
|
|
---
|
|
|
|
# --description--
|
|
|
|
When a condition for an `if` statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an `else` statement, an alternate block of code can be executed.
|
|
|
|
```js
|
|
if (num > 10) {
|
|
return "Bigger than 10";
|
|
} else {
|
|
return "10 or Less";
|
|
}
|
|
```
|
|
|
|
# --instructions--
|
|
|
|
Combine the `if` statements into a single `if/else` statement.
|
|
|
|
# --hints--
|
|
|
|
You should only have one `if` statement in the editor
|
|
|
|
```js
|
|
assert(code.match(/if/g).length === 1);
|
|
```
|
|
|
|
You should use an `else` statement
|
|
|
|
```js
|
|
assert(/else/g.test(code));
|
|
```
|
|
|
|
`testElse(4)` should return "5 or Smaller"
|
|
|
|
```js
|
|
assert(testElse(4) === '5 or Smaller');
|
|
```
|
|
|
|
`testElse(5)` should return "5 or Smaller"
|
|
|
|
```js
|
|
assert(testElse(5) === '5 or Smaller');
|
|
```
|
|
|
|
`testElse(6)` should return "Bigger than 5"
|
|
|
|
```js
|
|
assert(testElse(6) === 'Bigger than 5');
|
|
```
|
|
|
|
`testElse(10)` should return "Bigger than 5".
|
|
|
|
```js
|
|
assert(testElse(10) === 'Bigger than 5');
|
|
```
|
|
|
|
You should not change the code above or below the specified comments.
|
|
|
|
```js
|
|
assert(/var result = "";/.test(code) && /return result;/.test(code));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function testElse(val) {
|
|
var result = "";
|
|
// Only change code below this line
|
|
|
|
if (val > 5) {
|
|
result = "Bigger than 5";
|
|
}
|
|
|
|
if (val <= 5) {
|
|
result = "5 or Smaller";
|
|
}
|
|
|
|
// Only change code above this line
|
|
return result;
|
|
}
|
|
|
|
testElse(4);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function testElse(val) {
|
|
var result = "";
|
|
if(val > 5) {
|
|
result = "Bigger than 5";
|
|
} else {
|
|
result = "5 or Smaller";
|
|
}
|
|
return result;
|
|
}
|
|
```
|