--- id: 56533eb9ac21ba0edf2244da title: Introducing Else Statements challengeType: 1 videoUrl: https://scrimba.com/c/cek4Efq forumTopicId: 18207 localeTitle: Введение в новые заявления --- ## Description
Когда условие для оператора if истинно, выполняется блок кода после него. Как насчет того, когда это условие ложно? Обычно ничего не происходило. С помощью инструкции else может выполняться альтернативный блок кода.
если (num> 10) {
возвращение «Больше, чем 10»;
} else {
вернуть «10 или меньше»;
}
## Instructions
Объедините операторы if в один оператор if/else .
## Tests
```yml tests: - text: You should only have one if statement in the editor testString: assert(code.match(/if/g).length === 1); - text: You should use an else statement testString: assert(/else/g.test(code)); - text: testElse(4) should return "5 or Smaller" testString: assert(testElse(4) === "5 or Smaller"); - text: testElse(5) should return "5 or Smaller" testString: assert(testElse(5) === "5 or Smaller"); - text: testElse(6) should return "Bigger than 5" testString: assert(testElse(6) === "Bigger than 5"); - text: testElse(10) should return "Bigger than 5" testString: assert(testElse(10) === "Bigger than 5"); - text: Do not change the code above or below the lines. testString: assert(/var result = "";/.test(code) && /return result;/.test(code)); ```
## Challenge Seed
```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; } // Change this value to test testElse(4); ```
## Solution
```js function testElse(val) { var result = ""; if(val > 5) { result = "Bigger than 5"; } else { result = "5 or Smaller"; } return result; } ```