71 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 56533eb9ac21ba0edf2244da
title: 介绍 else 语句
challengeType: 1
videoUrl: 'https://scrimba.com/c/cek4Efq'
forumTopicId: 18207
---
# --description--
`if`语句的条件为真大括号里的代码执行那如果条件为假呢正常情况下什么也不会发生。使用else语句可以执行当条件为假时相应的代码。
```js
if (num > 10) {
return "Bigger than 10";
} else {
return "10 or Less";
}
```
# --instructions--
请把多个`if`语句合并为一个`if/else`语句。
# --hints--
你应该只有一个`if`表达式。
```js
assert(code.match(/if/g).length === 1);
```
你应该使用一个`else`表达式。
```js
assert(/else/g.test(code));
```
`testElse(4)`应该返回 "5 or Smaller"。
```js
assert(testElse(4) === '5 or Smaller');
```
`testElse(5)`应该返回 "5 or Smaller"。
```js
assert(testElse(5) === '5 or Smaller');
```
`testElse(6)`应该返回 "Bigger than 5"。
```js
assert(testElse(6) === 'Bigger than 5');
```
`testElse(10)`应该返回 "Bigger than 5"。
```js
assert(testElse(10) === 'Bigger than 5');
```
不要修改上面和下面的代码。
```js
assert(/var result = "";/.test(code) && /return result;/.test(code));
```
# --solutions--