2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d7b84367417b2b2512b35
|
|
|
|
|
challengeType: 1
|
2020-09-07 16:09:54 +08:00
|
|
|
|
forumTopicId: 301186
|
|
|
|
|
localeTitle: 捕获拼错的变量名和函数名
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-09-07 16:09:54 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
<code>console.log()</code>和<code>typeof</code>方法是检查中间值和程序输出类型的两种主要方法。 现在是时候了解一下 bug 出现的常见的情形。一个语法级别的问题是打字太快带来的低级拼写错误。
|
|
|
|
|
变量或函数名的错写、漏写或大小写弄混都会让浏览器尝试查找并不存在的东西,并报出“引用错误”。JavaScript 变量和函数名称区分大小写。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-09-07 16:09:54 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
修复代码中的两个拼写错误,以便<code>netWorkingCapital</code>计算有效。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-09-07 16:09:54 +08:00
|
|
|
|
- text: '检查计算 netWorkingCapital 值时使用的两个变量的拼写是否正确,控制台应该输出 "Net working capital is: 2"。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: 'assert(netWorkingCapital === 2);'
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 代码中不应存在拼写错误的变量。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!code.match(/recievables/g));
|
2020-09-07 16:09:54 +08:00
|
|
|
|
- text: 应在代码中声明并正确使用<code>receivables</code>变量。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(code.match(/receivables/g).length == 2);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 代码中不应存在拼写错误的变量。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!code.match(/payable;/g));
|
2020-09-07 16:09:54 +08:00
|
|
|
|
- text: 应在代码中声明并正确使用<code>payables</code>变量。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(code.match(/payables/g).length == 2);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
let receivables = 10;
|
|
|
|
|
let payables = 8;
|
|
|
|
|
let netWorkingCapital = recievables - payable;
|
|
|
|
|
console.log(`Net working capital is: ${netWorkingCapital}`);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
2020-09-07 16:09:54 +08:00
|
|
|
|
let receivables = 10;
|
|
|
|
|
let payables = 8;
|
|
|
|
|
let netWorkingCapital = receivables - payables;
|
|
|
|
|
console.log(`Net working capital is: ${netWorkingCapital}`);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-09-07 16:09:54 +08:00
|
|
|
|
</section>
|