2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: cf1111c1c11feddfaeb6bdef
|
|
|
|
title: Divide One Number by Another with JavaScript
|
|
|
|
challengeType: 1
|
2020-04-29 18:29:13 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/cqkbdAr'
|
|
|
|
forumTopicId: 17566
|
|
|
|
localeTitle: 除法运算
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-04-29 18:29:13 +08:00
|
|
|
<section id='description'>
|
|
|
|
我们可以在 JavaScript 中做除法运算。
|
|
|
|
JavaScript 中使用<code>/</code>符号做除法运算。
|
|
|
|
|
|
|
|
<strong>示例</strong>
|
|
|
|
|
|
|
|
```js
|
|
|
|
myVar = 16 / 2; // assigned 8
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2020-04-29 18:29:13 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
改变数值<code>0</code>来让变量<code>quotient</code>的值等于<code>2</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>quotient</code>的值等于 2。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(quotient === 2);
|
2020-04-29 18:29:13 +08:00
|
|
|
- text: 使用<code>/</code>运算符。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(/\d+\s*\/\s*\d+/.test(code));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
var quotient = 66 / 0;
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
### After Test
|
|
|
|
<div id='js-teardown'>
|
|
|
|
|
|
|
|
```js
|
2020-04-29 18:29:13 +08:00
|
|
|
(function(z){return 'quotient = '+z;})(quotient);
|
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
|
|
|
var quotient = 66 / 33;
|
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>
|