2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bd7123c9c441eddfaeb5bdef
|
|
|
|
|
challengeType: 1
|
2020-04-29 18:29:13 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/c9Me8t4'
|
|
|
|
|
forumTopicId: 301176
|
|
|
|
|
localeTitle: 理解布尔值
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-04-29 18:29:13 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
另一种数据类型是<dfn>布尔</dfn>(Boolean)。<code>布尔</code>值要么是<code>true</code>要么是<code>false</code>。它非常像电路开关,<code>true</code>是 “开”,<code>false</code>是 “关”。这两种状态是互斥的。
|
|
|
|
|
<strong>注意</strong><br><code>布尔值</code>是不带引号的,<code>"true"</code>和<code>"false"</code>是<code>字符串</code>而不是<code>布尔值</code>,在 JavaScript 中也没有特殊含义。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-04-29 18:29:13 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
修改<code>welcomeToBooleans</code>函数,让它返回<code>true</code>而不是<code>false</code>。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>welcomeToBooleans()</code>函数应该返回一个布尔值 (true/false)。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(typeof welcomeToBooleans() === 'boolean');
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>welcomeToBooleans()</code>应该返回 true。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(welcomeToBooleans() === true);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function welcomeToBooleans() {
|
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
// Only change code below this line.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
return false; // Change this line
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
// Only change code above this line.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### After Test
|
|
|
|
|
<div id='js-teardown'>
|
|
|
|
|
|
|
|
|
|
```js
|
2020-04-29 18:29:13 +08:00
|
|
|
|
welcomeToBooleans();
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```js
|
2020-04-29 18:29:13 +08:00
|
|
|
|
function welcomeToBooleans() {
|
|
|
|
|
return true; // Change this line
|
|
|
|
|
}
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|