fix(i18n): update Chinese translation of debugging (#38045)
Co-authored-by: Zhicheng Chen <chenzhicheng@dayuwuxian.com>
This commit is contained in:
@ -2,24 +2,28 @@
|
||||
id: 587d7b85367417b2b2512b3a
|
||||
title: Catch Arguments Passed in the Wrong Order When Calling a Function
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 调用函数时捕获以错误顺序传递的参数
|
||||
forumTopicId: 301184
|
||||
localeTitle: 调用函数时,捕获以错误顺序传递的参数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">继续讨论调用函数,需要注意的下一个错误是函数的参数是以错误的顺序提供的。如果参数是不同的类型,例如期望数组和整数的函数,则可能会引发运行时错误。如果参数是相同的类型(例如,所有整数),那么代码的逻辑将没有意义。确保以正确的顺序提供所有必需的参数以避免这些问题。 </section>
|
||||
<section id='description'>
|
||||
继续讨论调用函数,需要注意的下一个 bug 是函数的参数传递顺序错误。 如果参数分别是不同的类型,例如接受数组和整数两个参数的函数,参数顺序传错就可能会引发运行时错误。对于接受相同类型参数的函数,传错参数也会导致逻辑错误或运行结果错误。确保以正确的顺序提供所有必需的参数以避免这些问题。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">函数<code>raiseToPower</code>将基数提升为指数。不幸的是,它没有被正确调用 - 修复代码,因此<code>power</code>值是预期的8。 </section>
|
||||
<section id='instructions'>
|
||||
函数<code>raiseToPower</code>返回基数 (base) 的指数 (exponent) 次幂。不幸的是,它没有被正确调用 ———— 修改代码,使<code>power</code>的值为 8。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 你的代码应该固定可变<code>power</code>因此它等于2提升到3功率,而不是3增加到2功率。
|
||||
- text: 你应修复变量<code>power</code>,使其等于 2 的 3 次方,而不是 3 的 2 次方。
|
||||
testString: assert(power == 8);
|
||||
- text: 您的代码应使用<code>raiseToPower</code>函数调用的正确参数顺序。
|
||||
- text: 你调用<code>raiseToPower</code>函数时,传递参数的顺序应正确。
|
||||
testString: assert(code.match(/raiseToPower\(\s*?base\s*?,\s*?exp\s*?\);/g));
|
||||
|
||||
```
|
||||
@ -40,7 +44,6 @@ let base = 2;
|
||||
let exp = 3;
|
||||
let power = raiseToPower(exp, base);
|
||||
console.log(power);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -53,7 +56,14 @@ console.log(power);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function raiseToPower(b, e) {
|
||||
return Math.pow(b, e);
|
||||
}
|
||||
|
||||
let base = 2;
|
||||
let exp = 3;
|
||||
let power = raiseToPower(base, exp);
|
||||
console.log(power);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,24 +2,38 @@
|
||||
id: 587d7b85367417b2b2512b39
|
||||
title: Catch Missing Open and Closing Parenthesis After a Function Call
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 在函数调用后捕获缺失的打开和关闭括号
|
||||
forumTopicId: 301185
|
||||
localeTitle: 捕捉函数调用后缺少的左括号和右括号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">当函数或方法不接受任何参数时,您可能忘记在调用它时包括(空)开括号和右括号。通常,函数调用的结果会保存在变量中,以供代码中的其他用途使用。可以通过将变量值(或其类型)记录到控制台并看到一个设置为函数引用而不是函数返回的期望值来检测此错误。以下示例中的变量不同: <blockquote> function myFunction(){ <br>回归“你摇滚!”; <br> } <br> let varOne = myFunction; //设置为等于函数<br> let varTwo = myFunction(); //设置为等于字符串“You rock!” </blockquote></section>
|
||||
<section id='description'>
|
||||
当函数或方法不接受任何参数时,你可能忘记在调用它时加上空的左括号和右括号。通常,函数调用的结果会保存在变量中,供其他代码使用。可以通过将变量值(或其类型)打印到控制台,查看输出究竟是一个函数引用还是函数调用的返回值来检测这类错误。
|
||||
下面示例中的两个变量是不同的:
|
||||
|
||||
```js
|
||||
function myFunction() {
|
||||
return "You rock!";
|
||||
}
|
||||
let varOne = myFunction; // set to equal a function
|
||||
let varTwo = myFunction(); // set to equal the string "You rock!"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码,使变量<code>result</code>设置为调用函数<code>getNine</code>返回的值。 </section>
|
||||
<section id='instructions'>
|
||||
修复代码,把调用函数<code>getNine</code>的返回值赋给变量<code>result</code>。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应修复变量<code>result</code>以便将其设置为函数<code>getNine</code>返回的数字。
|
||||
- text: 你应该修复变量<code>result</code>使其为函数<code>getNine</code>的返回值。
|
||||
testString: assert(result == 9);
|
||||
- text: 您的代码应该调用<code>getNine</code>函数。
|
||||
- text: 你应该调用<code>getNine</code>函数。
|
||||
testString: assert(code.match(/getNine\(\)/g).length == 2);
|
||||
|
||||
```
|
||||
@ -40,7 +54,6 @@ function getNine() {
|
||||
|
||||
let result = getNine;
|
||||
console.log(result);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -53,7 +66,15 @@ console.log(result);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function getNine() {
|
||||
let x = 6;
|
||||
let y = 3;
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let result = getNine();
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
||||
|
@ -2,30 +2,35 @@
|
||||
id: 587d7b84367417b2b2512b35
|
||||
title: Catch Misspelled Variable and Function Names
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 捕获拼错的变量和函数名称
|
||||
forumTopicId: 301186
|
||||
localeTitle: 捕获拼错的变量名和函数名
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>console.log()</code>和<code>typeof</code>方法是检查中间值和程序输出类型的两种主要方法。现在是时候进入错误所采用的常见形式了。快速打字机可以同意的一个语法级问题是简单的拼写错误。变量或函数名称中的转置,丢失或错误大写字符将使浏览器查找不存在的对象 - 并以引用错误的形式进行抱怨。 JavaScript变量和函数名称区分大小写。 </section>
|
||||
<section id='description'>
|
||||
<code>console.log()</code>和<code>typeof</code>方法是检查中间值和程序输出类型的两种主要方法。 现在是时候了解一下 bug 出现的常见的情形。一个语法级别的问题是打字太快带来的低级拼写错误。
|
||||
变量或函数名的错写、漏写或大小写弄混都会让浏览器尝试查找并不存在的东西,并报出“引用错误”。JavaScript 变量和函数名称区分大小写。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码中的两个拼写错误,以便<code>netWorkingCapital</code>计算有效。 </section>
|
||||
<section id='instructions'>
|
||||
修复代码中的两个拼写错误,以便<code>netWorkingCapital</code>计算有效。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 检查netWorkingCapital计算中使用的两个变量的拼写,控制台输出应显示“净营运资金为:2”。
|
||||
- text: '检查计算 netWorkingCapital 值时使用的两个变量的拼写是否正确,控制台应该输出 "Net working capital is: 2"。'
|
||||
testString: 'assert(netWorkingCapital === 2);'
|
||||
- text: 代码中不应存在拼写错误的变量。
|
||||
testString: assert(!code.match(/recievables/g));
|
||||
- text: <code>receivables</code>在代码中声明并正确使用应<code>receivables</code>变量。
|
||||
- text: 应在代码中声明并正确使用<code>receivables</code>变量。
|
||||
testString: assert(code.match(/receivables/g).length == 2);
|
||||
- text: 代码中不应存在拼写错误的变量。
|
||||
testString: assert(!code.match(/payable;/g));
|
||||
- text: 应在组织中声明并正确使用<code>payables</code>变量。
|
||||
- text: 应在代码中声明并正确使用<code>payables</code>变量。
|
||||
testString: assert(code.match(/payables/g).length == 2);
|
||||
|
||||
```
|
||||
@ -42,7 +47,6 @@ let receivables = 10;
|
||||
let payables = 8;
|
||||
let netWorkingCapital = recievables - payable;
|
||||
console.log(`Net working capital is: ${netWorkingCapital}`);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -55,7 +59,10 @@ console.log(`Net working capital is: ${netWorkingCapital}`);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
let receivables = 10;
|
||||
let payables = 8;
|
||||
let netWorkingCapital = receivables - payables;
|
||||
console.log(`Net working capital is: ${netWorkingCapital}`);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,24 +2,46 @@
|
||||
id: 587d7b84367417b2b2512b37
|
||||
title: Catch Mixed Usage of Single and Double Quotes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 抓住单引号和双引号的混合使用
|
||||
forumTopicId: 301188
|
||||
localeTitle: 捕捉单引号和双引号的混合用法
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> JavaScript允许使用单个(“)和双(”“)引号来声明一个字符串。决定使用哪一个通常归结为个人偏好,但有一些例外。当字符串有收缩或另一个时,有两个选择很好引号中的文本片段。请注意,不要过早关闭字符串,这会导致语法错误。以下是混合引号的一些示例: <blockquote> //这些是正确的: <br> const grouchoContraction =“我度过了一个美好的夜晚,但事实并非如此。”; <br> const quoteInString =“Groucho Marx曾经说过'引用我的话说我被误引了'。”; <br> //这是不正确的: <br> const uhOhGroucho ='我度过了一个美妙的夜晚,但这不是它。'; </blockquote>当然,只使用一种报价样式是可以的。您可以使用反斜杠(\)转义字符来转义字符串中的引号: <blockquote> //正确使用相同的引号: <br> const allSameQuotes ='我度过了一个非常精彩的夜晚,但这不是它。'; </blockquote></section>
|
||||
<section id='description'>
|
||||
JavaScript允许使用单引号('')和双引号("")声明字符串。决定使用哪一个通常看个人偏好,但有一些例外。
|
||||
如果字符串中有缩写或存在一段带引号的文本,你就会明白为什么 JavaScript 允许两种引号了。请注意,不要提前用引号结束字符串,这会导致语法错误。
|
||||
下面是混合使用引号的一些示例:
|
||||
|
||||
```js
|
||||
// These are correct:
|
||||
const grouchoContraction = "I've had a perfectly wonderful evening, but this wasn't it.";
|
||||
const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quoted.'";
|
||||
// This is incorrect:
|
||||
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
|
||||
```
|
||||
|
||||
当然,只使用一种引号是可以的。你可以使用反斜杠 (<code>\\</code>) 转义字符来转义字符串中的引号:
|
||||
|
||||
```js
|
||||
// 一种引号的正确使用方式
|
||||
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复字符串,使其对<code>href</code>值使用不同的引号,或者转义现有的引号。在整个字符串周围保留双引号。 </section>
|
||||
<section id='instructions'>
|
||||
修复字符串,对<code>href</code>属性的值使用不同的引号,或者转义现有的引号。注意,整个字符串外面的双引号要保留。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '您的代码应该通过更改或转义它们来修复<code>href</code>值“#Home”周围的引号。'
|
||||
- text: "你应通过更改或转义来修复<code>href</code>的值 '#Home' 周围的引号。"
|
||||
testString: assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
|
||||
- text: 您的代码应该在整个字符串周围保留双引号。
|
||||
- text: 你应该在整个字符串外围保留双引号。
|
||||
testString: assert(code.match(/"<p>.*?<\/p>";/g));
|
||||
|
||||
```
|
||||
@ -34,7 +56,6 @@ tests:
|
||||
```js
|
||||
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
|
||||
console.log(innerHtml);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -47,7 +68,8 @@ console.log(innerHtml);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
|
||||
console.log(innerHtml);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,28 +2,51 @@
|
||||
id: 587d7b86367417b2b2512b3b
|
||||
title: Catch Off By One Errors When Using Indexing
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用索引时捕获一个错误
|
||||
forumTopicId: 301189
|
||||
localeTitle: 捕获使用索引的时候出现的错误
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">当您尝试定位字符串或数组的特定索引(切片或访问段)或循环索引时,会<code>Off by one errors</code> (有时称为OBOE)。 JavaScript索引从零开始,而不是一个,这意味着最后一个索引总是小于项目的长度。如果您尝试访问等于长度的索引,程序可能会抛出“索引超出范围”引用错误或打印<code>undefined</code> 。当您使用将索引范围作为参数的字符串或数组方法时,它有助于阅读文档并了解它们是否包含(指定索引处的项目是否是返回的一部分)。以下是一些错误的示例: <blockquote> let alphabet =“abcdefghijklmnopqrstuvwxyz”; <br>让len = alphabet.length; <br> for(let i = 0; i <= len; i ++){ <br> //最后循环一次太多次<br>的console.log(字母[I]); <br> } <br> for(let j = 1; j <len; j ++){ <br> //循环一次太少次并错过索引0处的第一个字符<br>的console.log(字母[J]); <br> } <br> for(let k = 0; k <len; k ++){ <br> // Goldilocks赞成 - 这是正确的<br>的console.log(字母表[K]); <br> } </blockquote></section>
|
||||
<section id='description'>
|
||||
当试图访问字符串或数组的特定索引(分割或访问一个片段)或循环索引时,有时会出现<code>Off by one errors</code>错误(有时称为 OBOE)。JavaScript 索引从<code>0</code>开始,而不是<code>1</code>,这意味着最后一个索引总会比字符串或数组的长度少 1。如果尝试访问等于长度的索引,程序可能会抛出“索引超出范围”引用错误或打印出<code>undefined</code>。
|
||||
当使用将索引范围作为参数的字符串或数组方法时,阅读相关的文档并了解参数中的索引的包含性(即是否考虑进返回值中)很重要。以下是一些错误的示例:
|
||||
|
||||
```js
|
||||
let alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
let len = alphabet.length;
|
||||
for (let i = 0; i <= len; i++) {
|
||||
// 在最后多了一次循环
|
||||
console.log(alphabet[i]);
|
||||
}
|
||||
for (let j = 1; j < len; j++) {
|
||||
// 循环少了一次,漏掉了索引 0 处的字符
|
||||
console.log(alphabet[j]);
|
||||
}
|
||||
for (let k = 0; k < len; k++) {
|
||||
// 不多不少,这才是正确的
|
||||
console.log(alphabet[k]);
|
||||
}
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复以下函数中的两个索引错误,以便将所有数字1到5打印到控制台。 </section>
|
||||
<section id='instructions'>
|
||||
修复以下函数中的两个索引错误,以便将 1 到 5 之间(包含 1 和 5)的所有数字打印到控制台。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该设置循环的初始条件,以便从第一个索引开始。
|
||||
- text: 你应该设置循环的初始条件,使循环从第一个索引开始。
|
||||
testString: assert(code.match(/i\s*?=\s*?0\s*?;/g).length == 1);
|
||||
- text: 您的代码应该修复循环的初始条件,以便索引从0开始。
|
||||
- text: 你应修复循环的初始条件,使循环从索引 0 开始。
|
||||
testString: assert(!code.match(/i\s?=\s*?1\s*?;/g));
|
||||
- text: 您的代码应设置循环的终端条件,以便它停在最后一个索引处。
|
||||
- text: 你应设置循环的终止条件,使循环在最后一个索引处停止。
|
||||
testString: assert(code.match(/i\s*?<\s*?len\s*?;/g).length == 1);
|
||||
- text: 您的代码应该修复循环的终端条件,使其在长度之前停止在1。
|
||||
- text: 你应修复循环的终止条件,使循环在索引为字符串长度减 1 时停止。
|
||||
testString: assert(!code.match(/i\s*?<=\s*?len;/g));
|
||||
|
||||
```
|
||||
@ -47,7 +70,6 @@ function countToFive() {
|
||||
}
|
||||
|
||||
countToFive();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -60,7 +82,18 @@ countToFive();
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function countToFive() {
|
||||
let firstFive = "12345";
|
||||
let len = firstFive.length;
|
||||
// Fix the line below
|
||||
for (let i = 0; i < len; i++) {
|
||||
// Do not alter code below this line
|
||||
console.log(firstFive[i]);
|
||||
}
|
||||
}
|
||||
|
||||
countToFive();
|
||||
```
|
||||
|
||||
/section>
|
||||
|
||||
</section>
|
||||
|
@ -1,25 +1,30 @@
|
||||
---
|
||||
id: 587d7b84367417b2b2512b36
|
||||
title: 'Catch Unclosed Parentheses, Brackets, Braces and Quotes'
|
||||
title: Catch Unclosed Parentheses, Brackets, Braces and Quotes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 抓住未封闭的圆括号,括号,括号和引号
|
||||
forumTopicId: 301190
|
||||
localeTitle: 捕获未闭合的括号、方括号、大括号和引号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">要注意的另一个语法错误是所有左括号,括号,花括号和引号都有一个结束对。当您编辑现有代码并使用其中一种类型插入项目时,会忘记忘记一件事。此外,在将代码块嵌套到其他代码块时要小心,例如将回调函数作为参数添加到方法中。避免这种错误的一种方法是,只要输入开头字符,立即包括结束匹配,然后将光标移回它们之间并继续编码。幸运的是,大多数现代代码编辑器会自动生成对的后半部分。 </section>
|
||||
<section id='description'>
|
||||
要注意的另一个语法错误是所有的小括号、方括号、花括号和引号都必须配对。当你编辑代码并插入新代码其中带有括号时,很容易忘记括号闭合。 此外,在将代码块嵌套到其他代码块时要小心,例如将回调函数作为参数添加到方法中。
|
||||
避免这种错误的一种方法是,一次性输入完这些符号,然后将光标移回它们之间继续编写。好在,现在大部分编辑器都会帮你自动补全。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码中的两对错误。 </section>
|
||||
<section id='instructions'>
|
||||
修复代码中的两个符号配对错误。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该修复数组中缺少的部分。
|
||||
- text: 你应该修复数组缺少的部分。
|
||||
testString: assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
|
||||
- text: 您的代码应该修复<code>.reduce()</code>方法的缺失部分。控制台输出应显示“数组值的总和为:6”。
|
||||
- text: '你应该修复<code>.reduce()</code>方法缺少的部分。控制台应输出 "Sum of array values is: 6"。'
|
||||
testString: 'assert(arraySum === 6);'
|
||||
|
||||
```
|
||||
@ -35,7 +40,6 @@ tests:
|
||||
let myArray = [1, 2, 3;
|
||||
let arraySum = myArray.reduce((previous, current => previous + current);
|
||||
console.log(`Sum of array values is: ${arraySum}`);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -48,7 +52,9 @@ console.log(`Sum of array values is: ${arraySum}`);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
let myArray = [1, 2, 3];
|
||||
let arraySum = myArray.reduce((previous, current) => previous + current);
|
||||
console.log(`Sum of array values is: ${arraySum}`);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,24 +2,41 @@
|
||||
id: 587d7b85367417b2b2512b38
|
||||
title: Catch Use of Assignment Operator Instead of Equality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 捕获使用赋值运算符而不是等式运算符
|
||||
forumTopicId: 301191
|
||||
localeTitle: 捕获使用赋值运算符而不是相等运算符
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">分支程序,即在满足某些条件时执行不同操作的程序,依赖于JavaScript中的<code>if</code> , <code>else if</code>和<code>else</code>语句。条件有时采取测试结果是否等于值的形式。这种逻辑(至少在英语中)是“如果x等于y,则......”,它可以使用<code>=</code>或赋值运算符逐字地转换为代码。这会导致程序中出现意外的控制流。如前面的挑战所述,JavaScript中的赋值运算符( <code>=</code> )为变量名赋值。并且<code>==</code>和<code>===</code>运算符检查相等性(严格相等的三重<code>===</code>测试,意味着值和类型都相同)。下面的代码将<code>x</code>指定为2,其值为<code>true</code> 。几乎JavaScript中的每个值都评估为<code>true</code> ,除了所谓的“falsy”值: <code>false</code> , <code>0</code> , <code>""</code> (空字符串), <code>NaN</code> , <code>undefined</code>和<code>null</code> 。 <blockquote>设x = 1; <br>让y = 2; <br> if(x = y){ <br> //此代码块将针对y的任何值运行(除非y最初设置为假) <br> } else { <br> //这个代码块是本例中应该运行的(但不会) <br> } </blockquote></section>
|
||||
<section id='description'>
|
||||
分支程序,即在满足某些条件时执行不同操作的程序,依赖于 JavaScript 中的<code>if</code>,<code>else if</code>、<code>else</code>语句。条件有时采取测试一个结果是否等于一个值的形式。
|
||||
这种逻辑可以表述为“如果 x 等于 y ,则......”,听起来像是可以使用<code>=</code>(即赋值运算符)。然而,这会导致程序中流程出问题。
|
||||
如前面的挑战所述,JavaScript 中的赋值运算符 (<code>=</code>) 是用来为变量名赋值的。并且<code>==</code>和<code>===</code>运算符检查相等性(三等号<code>===</code>是用来测试是否严格相等的,严格相等的意思是值和类型都必须相同)。
|
||||
下面的代码将<code>x</code>赋值为 2,表达式<code>x = y</code>会在执行后得到<code>true</code>。JavaScript 会把大部分的值都视为<code>true</code>,除了所谓的 "falsy" 值,即:<code>false</code>、<code>0</code>、<code>""</code>(空字符串)、<code>NaN</code>、<code>undefined</code> 和 <code>null</code>。
|
||||
|
||||
```js
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
if (x = y) {
|
||||
// 除了 "falsy" 值以外 y 为任意值时这个代码块都将执行
|
||||
} else {
|
||||
// 按本例用意这个代码块应该执行(但其实不会)。
|
||||
}
|
||||
```
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复条件,以便程序运行正确的分支,并为<code>result</code>分配适当的值。 </section>
|
||||
<section id='instructions'>
|
||||
修复条件语句,以便程序运行正确的分支,并给<code>result</code>赋上正确的值。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该修复条件,以便检查是否相等,而不是使用赋值。
|
||||
- text: 你应该修复条件语句,使其判断是否相等,而不是赋值。
|
||||
testString: assert(result == "Not equal!");
|
||||
- text: 条件可以使用<code>==</code>或<code>===</code>来测试相等性。
|
||||
- text: 条件语句可以使用<code>==</code>或<code>===</code>来测试是否相等。
|
||||
testString: assert(code.match(/x\s*?===?\s*?y/g));
|
||||
|
||||
```
|
||||
@ -43,7 +60,6 @@ if(x = y) {
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -56,7 +72,17 @@ console.log(result);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
let x = 7;
|
||||
let y = 9;
|
||||
let result = "to come";
|
||||
|
||||
if(x === y) {
|
||||
result = "Equal!";
|
||||
} else {
|
||||
result = "Not equal!";
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,24 +2,39 @@
|
||||
id: 587d7b86367417b2b2512b3d
|
||||
title: Prevent Infinite Loops with a Valid Terminal Condition
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用有效的终端条件防止无限循环
|
||||
forumTopicId: 301192
|
||||
localeTitle: 使用有效的终止条件防止无限循环
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">最后一个话题是可怕的无限循环。当您需要程序运行代码块一定次数或满足条件时,循环是很好的工具,但是它们需要终止条件来结束循环。无限循环可能会冻结或崩溃浏览器,并导致一般程序执行混乱,没有人想要。在本节的介绍中有一个无限循环的例子 - 它没有终止条件来摆脱<code>loopy()</code>内的<code>while</code>循环。不要叫这个功能! <blockquote> function loopy(){ <br> while(true){ <br> console.log(“Hello,world!”); <br> } <br> } </blockquote>程序员的工作是确保最终达到终止条件,该条件告诉程序何时突破循环代码。一个错误是从终端条件向错误方向递增或递减计数器变量。另一个是在循环代码中意外重置计数器或索引变量,而不是递增或递减它。 </section>
|
||||
<section id='description'>
|
||||
最后一个话题是可怕的无限循环。当需要程序运行代码块一定次数或满足条件时,循环是很好的工具,但是它们需要终止条件来结束循环。无限循环可能会使浏览器冻结或崩溃,并导致程序执行混乱,没有人想要这样的结果。
|
||||
在本节的介绍中有一个无限循环的例子——它没有终止条件来摆脱<code>loopy()</code>内的<code>while</code>循环。不要调用这个函数!
|
||||
|
||||
```js
|
||||
function loopy() {
|
||||
while(true) {
|
||||
console.log("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
程序员的工作是确保最终达到终止条件,该条件告诉程序何时跳出循环。有一种错误是从终端条件向错误方向递增或递减计数器变量。另一种是在循环代码中意外重置计数器或索引变量,而不是递增或递减它。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> <code>myFunc()</code>函数包含一个无限循环,因为终端条件<code>i != 4</code>将永远不会计算为<code>false</code> (并且会中断循环) - <code>i</code>将每次递增2,然后跳过4,因为<code>i</code>是奇数启动。固定在终端条件比较运算符因此该循环仅运行<code>i</code>小于或等于4。 </section>
|
||||
<section id='instructions'>
|
||||
<code>myFunc()</code>函数包含一个无限循环,因为终止条件<code>i != 4</code>永远不会为<code>false</code>(并中断循环) -<code>i</code>将每次递增 2,然后跳过 4,因为<code>i</code>是从奇数开始递增。在终端条件中输入比较运算符,使循环仅在<code>i</code>小于或等于 4 的情况下运行。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该更改<code>for</code>循环的终端条件(中间部分)中的比较运算符。
|
||||
- text: 你应该在<code>for</code>循环的终止条件(中间部分)中更改比较运算符。
|
||||
testString: assert(code.match(/i\s*?<=\s*?4;/g).length == 1);
|
||||
- text: 您的代码应该在循环的终端条件中修复比较运算符。
|
||||
- text: 你应该修改比较运算符来避免出现死循环。
|
||||
testString: assert(!code.match(/i\s*?!=\s*?4;/g));
|
||||
|
||||
```
|
||||
@ -37,7 +52,6 @@ function myFunc() {
|
||||
console.log("Still going!");
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -50,7 +64,11 @@ function myFunc() {
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function myFunc() {
|
||||
for (let i = 1; i <= 4; i += 2) {
|
||||
console.log("Still going!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,27 +2,34 @@
|
||||
id: 587d7b83367417b2b2512b37
|
||||
title: Understanding the Differences between the freeCodeCamp and Browser Console
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 了解freeCodeCamp和浏览器控制台之间的差异
|
||||
forumTopicId: 301193
|
||||
localeTitle: 了解 freeCodeCamp 和浏览器控制台之间的差异
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">您可能已经注意到一些freeCodeCamp JavaScript挑战包括他们自己的控制台。此控制台的行为与您在上一次挑战中使用的浏览器控制台略有不同。以下挑战旨在强调freeCodeCamp控制台与浏览器控制台之间的一些差异。首先,浏览器控制台。当您在浏览器中加载并运行普通JavaScript文件时, <code>console.log()</code>语句将准确打印您告诉他们打印到浏览器控制台的确切次数。在浏览器中的文本编辑器中,过程略有不同,最初可能会让人感到困惑。传递给文本编辑器块中的<code>console.log()</code>值运行每组测试以及您在代码中进行的任何函数调用的一次。这有助于一些有趣的行为,并且可能会在开始时将您绊倒,因为您希望只看到一次的记录值可能会打印出更多次,具体取决于测试次数和传递给这些测试的值。如果您只想查看单个输出而不必担心运行测试周期,可以使用<code>console.clear()</code> 。 </section>
|
||||
<section id='description'>
|
||||
你可能已经注意到一些 freeCodeCamp JavaScript 的挑战有自己的控制台。这些控制台的行为与上一次挑战中使用的浏览器控制台略有不同。
|
||||
以下挑战旨在强调 freeCodeCamp 控制台与浏览器控制台之间的一些差异。
|
||||
对于浏览器控制台。当在浏览器中加载并运行 JavaScript 文件时,<code>console.log()</code>语句会在控制台中按照调用的次数准确地打印出要求的内容。然而,在 freeCodeCamp 的代码编辑器中使用<code>console.log()</code>会略有不同,一开始可能会让你感到困惑。
|
||||
在 freeCodeCamp 代码编辑器中,传给<code>console.log()</code>的值会在每组测试执行的时候输出。另外,如果在代码中还手动调用过挑战题目的函数,调用几次就会增加几次传入值的输出。
|
||||
这就产生了一些有趣的行为,并可能在一开始就让你感到困惑,因为你觉得只会输出一次的值可能会输出多次,具体次数取决于挑战题目本身测试的数量以及这些测试调用挑战函数的方式。
|
||||
如果你不打算执行挑战的测试,而只想查看自己调用<code>console.log()</code>的输出,可以使用<code>console.clear()</code>。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">使用<code>console.log()</code>在指示的代码中打印变量。 </section>
|
||||
<section id='instructions'>
|
||||
首先,使用 <code>console.clear()</code> 清空浏览器控制台。然后使用<code>console.log()</code>在代码中指定的位置打印 <code>output</code> 变量。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 使用<code>console.log()</code>打印<code>outputTwo</code>变量。在浏览器控制台中,这应该打印出变量的值两次。
|
||||
testString: 'assert(code.match(/console\.log\(outputTwo\)/g), "Use <code>console.log()</code> to print the <code>outputTwo</code> variable. In your Browser Console this should print out the value of the variable two times.");'
|
||||
- text: 使用<code>console.log()</code>打印<code>outputOne</code>变量。
|
||||
testString: 'assert(code.match(/console\.log\(outputOne\)/g), "Use <code>console.log()</code> to print the <code>outputOne</code> variable.");'
|
||||
- text: 使用<code>console.clear()</code>修改输出,以便<code>outputOne</code>变量只输出一次。
|
||||
testString: 'assert(code.match(/^(\s*console.clear\(\);?\s*)$/gm), "Use <code>console.clear()</code> to modify your output so that <code>outputOne</code> variable only outputs once.");'
|
||||
- text: 应该使用 <code>console.clear()</code> 来清空浏览器控制台。
|
||||
testString: const removeJSComments = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); const noSpaces = removeJSComments.replace(/\s/g, ''); assert(noSpaces.match(/console.clear\(\)/));
|
||||
- text: 使用<code>console.log()</code>输出变量<code>output</code>的值。
|
||||
testString: const noSpaces = code.replace(/\s/g, ''); assert(noSpaces.match(/console\.log\(output\)/));
|
||||
|
||||
```
|
||||
|
||||
@ -34,17 +41,15 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Open your browser console
|
||||
let outputTwo = "This will print to the browser console 2 times";
|
||||
// Use console.log() to print the outputTwo variable
|
||||
// Open your browser console.
|
||||
let output = "Get this to log once in the browser console and twice in the freeCodeCamp console";
|
||||
// Use console.clear() on the next line to clear the browser console.
|
||||
|
||||
|
||||
let outputOne = "Try to get this to log only once to the browser console";
|
||||
// Use console.clear() in the next line to print the outputOne only once
|
||||
// Use console.log() to print the output variable.
|
||||
|
||||
|
||||
// Use console.log() to print the outputOne variable
|
||||
|
||||
// Check the two consoles to see the difference. The freeCodeCamp console should have printed the variable twice, once for each test of this challenge. The browser console should only print the variable once because you cleared it first.
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -56,8 +61,18 @@ let outputOne = "Try to get this to log only once to the browser console";
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
|
||||
```js
|
||||
// solution required
|
||||
// Open your browser console.
|
||||
let output = "Get this to log once in the browser console and twice in the freeCodeCamp console";
|
||||
// Use console.clear() on the next line to clear the browser console.
|
||||
console.clear();
|
||||
|
||||
// Use console.log() to print the output variable.
|
||||
console.log(output);
|
||||
|
||||
// Check the two consoles to see the difference. The freeCodeCamp console should have printed the variable twice, one for each test of this challenge. The browser console should only print the variable once becuase you cleared it first.
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
||||
|
@ -2,26 +2,31 @@
|
||||
id: 587d7b86367417b2b2512b3c
|
||||
title: Use Caution When Reinitializing Variables Inside a Loop
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 在循环内重新初始化变量时请小心
|
||||
forumTopicId: 301194
|
||||
localeTitle: 重新初始化循环中的变量时要小心
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">有时需要在循环中保存信息,增加计数器或重置变量。一个潜在的问题是变量要么重新初始化,要么不重新初始化,反之亦然。如果您不小心重置了用于终端条件的变量,导致无限循环,这将特别危险。使用<code>console.log()</code>在循环的每个循环中打印变量值可以发现与重置相关的错误行为,或者无法重置变量。 </section>
|
||||
<section id='description'>
|
||||
有时需要在循环中保存信息以增加计数器或重置变量。一个潜在的问题是变量什么时候该重新初始化,什么时候不该重新初始化,反之亦然。如果你不小心重置了用于终止条件的变量,导致无限循环,这将特别危险。
|
||||
使用<code>console.log()</code>在每个循环中打印变量值可以发现与重置相关的错误或者重置变量失败。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">以下函数应该创建一个具有<code>m</code>行和<code>n</code>列零的二维数组。不幸的是,它没有产生预期的输出,因为<code>row</code>变量没有在外部循环中重新初始化(设置回空数组)。修复代码,使其返回正确的3x2零数组,看起来像<code>[[0, 0], [0, 0], [0, 0]]</code> 。 </section>
|
||||
<section id='instructions'>
|
||||
以下函数应该创建一个具有<code>m</code>行和<code>n</code>列“零”的二维数组。不幸的是,它没有产生预期的输出,因为<code>row</code>变量没有在外部循环中重新初始化(设置回空数组)。修改代码,使其正确地返回包含 3 行 2 列“零”的二维数组,即<code>[[0, 0], [0, 0], [0, 0]]</code>。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该将<code>matrix</code>变量设置为一个数组,每个数组包含3行,每列2列零。
|
||||
- text: 你应将变量<code>matrix</code>设置为 3 行 2 列“零”的二维数组。
|
||||
testString: assert(JSON.stringify(matrix) == "[[0,0],[0,0],[0,0]]");
|
||||
- text: <code>matrix</code>变量应该有3行。
|
||||
- text: 变量<code>matrix</code>应有 3 行。
|
||||
testString: assert(matrix.length == 3);
|
||||
- text: <code>matrix</code>变量每行应有2列。
|
||||
- text: 变量<code>matrix</code>每行应有 2 列。
|
||||
testString: assert(matrix[0].length == 2 && matrix[1].length === 2 && matrix[2].length === 2);
|
||||
|
||||
```
|
||||
@ -53,7 +58,6 @@ function zeroArray(m, n) {
|
||||
|
||||
let matrix = zeroArray(3, 2);
|
||||
console.log(matrix);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -66,7 +70,25 @@ console.log(matrix);
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function zeroArray(m, n) {
|
||||
// Creates a 2-D array with m rows and n columns of zeroes
|
||||
let newArray = [];
|
||||
for (let i = 0; i < m; i++) {
|
||||
let row = [];
|
||||
// Adds the m-th row into newArray
|
||||
|
||||
for (let j = 0; j < n; j++) {
|
||||
// Pushes n zeroes into the current row to create the columns
|
||||
row.push(0);
|
||||
}
|
||||
// Pushes the current row, which now has n zeroes in it, to the array
|
||||
newArray.push(row);
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
let matrix = zeroArray(3, 2);
|
||||
console.log(matrix);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
@ -2,22 +2,30 @@
|
||||
id: 587d7b83367417b2b2512b33
|
||||
title: Use the JavaScript Console to Check the Value of a Variable
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用JavaScript控制台检查变量的值
|
||||
forumTopicId: 18372
|
||||
localeTitle: 使用控制台检查变量值
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Chrome和Firefox都有出色的JavaScript控制台,也称为DevTools,用于调试JavaScript。您可以在Chrome的菜单或FireFox菜单中的Web控制台中找到开发人员工具。如果您使用的是其他浏览器或手机,我们强烈建议您使用桌面版Firefox或Chrome。 <code>console.log()</code>方法将打印其括号内的输出“打印”到控制台,这可能是最有用的调试工具。将它放在代码中的关键点可以显示变量的中间值。在查看输出之前,最好先了解输出应该是什么。在整个代码中使用检查点来查看计算状态将有助于缩小问题所在。这是打印'Hello world!'的示例到控制台: <code>console.log('Hello world!');</code> </section>
|
||||
<section id='description'>
|
||||
Chrome 和 Firefox 都有出色的 JavaScript 控制台(也称为 DevTools),可以用来调试 JavaScript 代码
|
||||
可以在 Chrome 的菜单中找到“开发者工具”或 FireFox 的菜单中的 “Web 控制台”。如果你使用其他浏览器或手机,我们强烈建议你切换到桌面版 Firefox 或 Chrome。
|
||||
<code>console.log()</code>方法可能是最有用的调试工具,它可以将括号中的内容输出到控制台,将它放在代码中的关键点可以显示变量在当时的值。在查看输出之前,最好先想清楚输出应该是什么。在代码的合适位置打点来查看变量状态有助于定位问题。
|
||||
下面是输出 'Hello world!' 到控制台的示例:
|
||||
<code>console.log('Hello world!');</code>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">使用<code>console.log()</code>方法打印代码中记录的变量<code>a</code>的值。 </section>
|
||||
<section id='instructions'>
|
||||
请使用<code>console.log()</code>方法在代码中注明的地方输出变量<code>a</code>的值。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应使用<code>console.log()</code>来检查变量<code>a</code>的值。
|
||||
- text: 你应使用<code>console.log()</code>来检查变量<code>a</code>的值。
|
||||
testString: assert(code.match(/console\.log\(a\)/g));
|
||||
|
||||
```
|
||||
@ -38,7 +46,6 @@ a++;
|
||||
|
||||
let sumAB = a + b;
|
||||
console.log(sumAB);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -50,8 +57,10 @@ console.log(sumAB);
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
|
||||
```js
|
||||
// solution required
|
||||
var a = 5; console.log(a);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
||||
|
@ -2,26 +2,39 @@
|
||||
id: 587d7b84367417b2b2512b34
|
||||
title: Use typeof to Check the Type of a Variable
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用typeof检查变量的类型
|
||||
forumTopicId: 18374
|
||||
localeTitle: 使用 type of 检查变量的类型
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">您可以使用<code>typeof</code>检查变量的数据结构或类型。在处理多种数据类型时,这在调试时很有用。如果您认为您正在添加两个数字,但其中一个实际上是一个字符串,则结果可能是意外的。类型错误可能潜伏在计算或函数调用中。特别是当您以JavaScript Object Notation(JSON)对象的形式访问和使用外部数据时要特别小心。以下是使用<code>typeof</code>一些示例: <blockquote> console.log(typeof“”); //输出“string” <br> console.log(typeof 0); //输出“数字” <br> console.log(typeof []); //输出“对象” <br> console.log(typeof {}); //输出“对象” </blockquote> JavaScript识别六种原始(不可变)数据类型: <code>Boolean</code> , <code>Null</code> , <code>Undefined</code> , <code>Number</code> , <code>String</code>和<code>Symbol</code> (ES6新增)和可变项的一种类型: <code>Object</code> 。请注意,在JavaScript中,数组在技术上是一种对象。 </section>
|
||||
<section id='description'>
|
||||
可以使用<code>typeof</code>检查变量的数据结构或类型。在处理多种数据类型时,<code>typeof</code>会对调试很有帮助。如果想计算两数之和,但实际传入了一个字符串参数,则结果可能是错误的。类型错误可能隐藏在计算或函数调用中。当你以 JavaScript 对象(JSON)的形式访问和使用外部数据时尤其要小心。
|
||||
下面是使用<code>typeof</code>的一些示例:
|
||||
|
||||
```js
|
||||
console.log(typeof ""); // 输出 "string"
|
||||
console.log(typeof 0); // 输出 "number"
|
||||
console.log(typeof []); // 输出 "object"
|
||||
console.log(typeof {}); // 输出 "object"
|
||||
```
|
||||
JavaScript 有六种原始(不可变)数据类型:<code>Boolean</code>,<code>Null</code>,<code>Undefined</code>,<code>Number</code>,<code>String</code>, 和<code>Symbol</code>(ES6 新增)和一种可变的数据类型:<code>Object</code>。注意,在 JavaScript 中,数组在本质上是一种对象
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">添加两个<code>console.log()</code>语句来检查<code>typeof</code>每两个变量的<code>seven</code>和<code>three</code>中的代码。 </section>
|
||||
<section id='instructions'>
|
||||
添加两个<code>console.log()</code>语句来检查代码中的两个变量<code>seven</code>和<code>three</code>的 <code>typeof</code>值。
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应在两个<code>console.log()</code>语句中使用<code>typeof</code>来检查变量的类型。
|
||||
- text: 你应在两个<code>console.log()</code>语句中使用<code>typeof</code>来检查变量的类型。
|
||||
testString: assert(code.match(/console\.log\(typeof[\( ].*\)?\)/g).length == 2);
|
||||
- text: 您的代码应使用<code>typeof</code>来检查变量类型<code>seven</code> 。
|
||||
- text: 你应使用<code>typeof</code>来检查变量<code>seven</code>的类型。
|
||||
testString: assert(code.match(/typeof[\( ]seven\)?/g));
|
||||
- text: 您的代码应使用<code>typeof</code>来检查变量的类型<code>three</code> 。
|
||||
- text: 你应使用<code>typeof</code>来检查变量<code>three</code>的类型。
|
||||
testString: assert(code.match(/typeof[\( ]three\)?/g));
|
||||
|
||||
```
|
||||
@ -50,8 +63,10 @@ console.log(seven + three);
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
|
||||
```js
|
||||
// solution required
|
||||
let seven = 7;let three = "3";console.log(typeof seven);
|
||||
console.log(typeof three);
|
||||
```
|
||||
|
||||
/section>
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user