Add languages Russian, Arabic, Chinese, Portuguese (#18305)
This commit is contained in:
committed by
mrugesh mohapatra
parent
09d3eca712
commit
2ca3a2093f
@ -0,0 +1,58 @@
|
||||
---
|
||||
id: 587d7b85367417b2b2512b3a
|
||||
title: Catch Arguments Passed in the Wrong Order When Calling a Function
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 调用函数时捕获以错误顺序传递的参数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">继续讨论调用函数,需要注意的下一个错误是函数的参数是以错误的顺序提供的。如果参数是不同的类型,例如期望数组和整数的函数,则可能会引发运行时错误。如果参数是相同的类型(例如,所有整数),那么代码的逻辑将没有意义。确保以正确的顺序提供所有必需的参数以避免这些问题。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">函数<code>raiseToPower</code>将基数提升为指数。不幸的是,它没有被正确调用 - 修复代码,因此<code>power</code>值是预期的8。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 你的代码应该固定可变<code>power</code>因此它等于2提升到3功率,而不是3增加到2功率。
|
||||
testString: 'assert(power == 8, "Your code should fix the variable <code>power</code> so it equals 2 raised to the 3rd power, not 3 raised to the 2nd power.");'
|
||||
- text: 您的代码应使用<code>raiseToPower</code>函数调用的正确参数顺序。
|
||||
testString: 'assert(code.match(/raiseToPower\(\s*?base\s*?,\s*?exp\s*?\);/g), "Your code should use the correct order of the arguments for the <code>raiseToPower</code> function call.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function raiseToPower(b, e) {
|
||||
return Math.pow(b, e);
|
||||
}
|
||||
|
||||
let base = 2;
|
||||
let exp = 3;
|
||||
let power = raiseToPower(exp, base);
|
||||
console.log(power);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,58 @@
|
||||
---
|
||||
id: 587d7b85367417b2b2512b39
|
||||
title: Catch Missing Open and Closing Parenthesis After a Function Call
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 在函数调用后捕获缺失的打开和关闭括号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">当函数或方法不接受任何参数时,您可能忘记在调用它时包括(空)开括号和右括号。通常,函数调用的结果会保存在变量中,以供代码中的其他用途使用。可以通过将变量值(或其类型)记录到控制台并看到一个设置为函数引用而不是函数返回的期望值来检测此错误。以下示例中的变量不同: <blockquote> function myFunction(){ <br>回归“你摇滚!”; <br> } <br> let varOne = myFunction; //设置为等于函数<br> let varTwo = myFunction(); //设置为等于字符串“You rock!” </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码,使变量<code>result</code>设置为调用函数<code>getNine</code>返回的值。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应修复变量<code>result</code>以便将其设置为函数<code>getNine</code>返回的数字。
|
||||
testString: 'assert(result == 9, "Your code should fix the variable <code>result</code> so it is set to the number that the function <code>getNine</code> returns.");'
|
||||
- text: 您的代码应该调用<code>getNine</code>函数。
|
||||
testString: 'assert(code.match(/getNine\(\)/g).length == 2, "Your code should call the <code>getNine</code> function.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function getNine() {
|
||||
let x = 6;
|
||||
let y = 3;
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let result = getNine;
|
||||
console.log(result);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
id: 587d7b84367417b2b2512b35
|
||||
title: Catch Misspelled Variable and Function Names
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 捕获拼错的变量和函数名称
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>console.log()</code>和<code>typeof</code>方法是检查中间值和程序输出类型的两种主要方法。现在是时候进入错误所采用的常见形式了。快速打字机可以同意的一个语法级问题是简单的拼写错误。变量或函数名称中的转置,丢失或错误大写字符将使浏览器查找不存在的对象 - 并以引用错误的形式进行抱怨。 JavaScript变量和函数名称区分大小写。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码中的两个拼写错误,以便<code>netWorkingCapital</code>计算有效。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 检查netWorkingCapital计算中使用的两个变量的拼写,控制台输出应显示“净营运资金为:2”。
|
||||
testString: 'assert(netWorkingCapital === 2, "Check the spelling of the two variables used in the netWorkingCapital calculation, the console output should show that "Net working capital is: 2".");'
|
||||
- text: 代码中不应存在拼写错误的变量。
|
||||
testString: 'assert(!code.match(/recievables/g), "There should be no instances of mis-spelled variables in the code.");'
|
||||
- text: <code>receivables</code>在代码中声明并正确使用应<code>receivables</code>变量。
|
||||
testString: 'assert(code.match(/receivables/g).length == 2, "The <code>receivables</code> variable should be declared and used properly in the code.");'
|
||||
- text: 代码中不应存在拼写错误的变量。
|
||||
testString: 'assert(!code.match(/payable;/g), "There should be no instances of mis-spelled variables in the code.");'
|
||||
- text: 应在组织中声明并正确使用<code>payables</code>变量。
|
||||
testString: 'assert(code.match(/payables/g).length == 2, "The <code>payables</code> variable should be declared and used properly in the code.");'
|
||||
|
||||
```
|
||||
|
||||
</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
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,52 @@
|
||||
---
|
||||
id: 587d7b84367417b2b2512b37
|
||||
title: Catch Mixed Usage of Single and Double Quotes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
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>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复字符串,使其对<code>href</code>值使用不同的引号,或者转义现有的引号。在整个字符串周围保留双引号。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '您的代码应该通过更改或转义它们来修复<code>href</code>值“#Home”周围的引号。'
|
||||
testString: 'assert(code.match(/<a href=\s*?("|\\")#Home\1\s*?>/g), "Your code should fix the quotes around the <code>href</code> value "#Home" by either changing or escaping them.");'
|
||||
- text: 您的代码应该在整个字符串周围保留双引号。
|
||||
testString: 'assert(code.match(/"<p>.*?<\/p>";/g), "Your code should keep the double quotes around the entire string.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
|
||||
console.log(innerHtml);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,65 @@
|
||||
---
|
||||
id: 587d7b86367417b2b2512b3b
|
||||
title: Catch Off By One Errors When Using Indexing
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
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>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复以下函数中的两个索引错误,以便将所有数字1到5打印到控制台。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该设置循环的初始条件,以便从第一个索引开始。
|
||||
testString: 'assert(code.match(/i\s*?=\s*?0\s*?;/g).length == 1, "Your code should set the initial condition of the loop so it starts at the first index.");'
|
||||
- text: 您的代码应该修复循环的初始条件,以便索引从0开始。
|
||||
testString: 'assert(!code.match(/i\s?=\s*?1\s*?;/g), "Your code should fix the initial condition of the loop so that the index starts at 0.");'
|
||||
- text: 您的代码应设置循环的终端条件,以便它停在最后一个索引处。
|
||||
testString: 'assert(code.match(/i\s*?<\s*?len\s*?;/g).length == 1, "Your code should set the terminal condition of the loop so it stops at the last index.");'
|
||||
- text: 您的代码应该修复循环的终端条件,使其在长度之前停止在1。
|
||||
testString: 'assert(!code.match(/i\s*?<=\s*?len;/g), "Your code should fix the terminal condition of the loop so that it stops at 1 before the length.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function countToFive() {
|
||||
let firstFive = "12345";
|
||||
let len = firstFive.length;
|
||||
// Fix the line below
|
||||
for (let i = 1; i <= len; i++) {
|
||||
// Do not alter code below this line
|
||||
console.log(firstFive[i]);
|
||||
}
|
||||
}
|
||||
|
||||
countToFive();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,53 @@
|
||||
---
|
||||
id: 587d7b84367417b2b2512b36
|
||||
title: 'Catch Unclosed Parentheses, Brackets, Braces and Quotes'
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 抓住未封闭的圆括号,括号,括号和引号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">要注意的另一个语法错误是所有左括号,括号,花括号和引号都有一个结束对。当您编辑现有代码并使用其中一种类型插入项目时,会忘记忘记一件事。此外,在将代码块嵌套到其他代码块时要小心,例如将回调函数作为参数添加到方法中。避免这种错误的一种方法是,只要输入开头字符,立即包括结束匹配,然后将光标移回它们之间并继续编码。幸运的是,大多数现代代码编辑器会自动生成对的后半部分。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复代码中的两对错误。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该修复数组中缺少的部分。
|
||||
testString: 'assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g), "Your code should fix the missing piece of the array.");'
|
||||
- text: 您的代码应该修复<code>.reduce()</code>方法的缺失部分。控制台输出应显示“数组值的总和为:6”。
|
||||
testString: 'assert(arraySum === 6, "Your code should fix the missing piece of the <code>.reduce()</code> method. The console output should show that "Sum of array values is: 6".");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let myArray = [1, 2, 3;
|
||||
let arraySum = myArray.reduce((previous, current => previous + current);
|
||||
console.log(`Sum of array values is: ${arraySum}`);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
id: 587d7b85367417b2b2512b38
|
||||
title: Catch Use of Assignment Operator Instead of Equality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
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>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">修复条件,以便程序运行正确的分支,并为<code>result</code>分配适当的值。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该修复条件,以便检查是否相等,而不是使用赋值。
|
||||
testString: 'assert(result == "Not equal!", "Your code should fix the condition so it checks for equality, instead of using assignment.");'
|
||||
- text: 条件可以使用<code>==</code>或<code>===</code>来测试相等性。
|
||||
testString: 'assert(code.match(/x\s*?===?\s*?y/g), "The condition can use either <code>==</code> or <code>===</code> to test for equality.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let x = 7;
|
||||
let y = 9;
|
||||
let result = "to come";
|
||||
|
||||
if(x = y) {
|
||||
result = "Equal!";
|
||||
} else {
|
||||
result = "Not equal!";
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,55 @@
|
||||
---
|
||||
id: 587d7b86367417b2b2512b3d
|
||||
title: Prevent Infinite Loops with a Valid Terminal Condition
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
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>
|
||||
|
||||
## 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>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该更改<code>for</code>循环的终端条件(中间部分)中的比较运算符。
|
||||
testString: 'assert(code.match(/i\s*?<=\s*?4;/g).length == 1, "Your code should change the comparison operator in the terminal condition (the middle part) of the <code>for</code> loop.");'
|
||||
- text: 您的代码应该在循环的终端条件中修复比较运算符。
|
||||
testString: 'assert(!code.match(/i\s*?!=\s*?4;/g), "Your code should fix the comparison operator in the terminal condition of the loop.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function myFunc() {
|
||||
for (let i = 1; i != 4; i += 2) {
|
||||
console.log("Still going!");
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
id: 587d7b83367417b2b2512b37
|
||||
title: Understanding the Differences between the freeCodeCamp and Browser Console
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 了解freeCodeCamp和浏览器控制台之间的差异
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">您可能已经注意到一些freeCodeCamp JavaScript挑战包括他们自己的控制台。此控制台的行为与您在上一次挑战中使用的浏览器控制台略有不同。以下挑战旨在强调freeCodeCamp控制台与浏览器控制台之间的一些差异。首先,浏览器控制台。当您在浏览器中加载并运行普通JavaScript文件时, <code>console.log()</code>语句将准确打印您告诉他们打印到浏览器控制台的确切次数。在浏览器中的文本编辑器中,过程略有不同,最初可能会让人感到困惑。传递给文本编辑器块中的<code>console.log()</code>值运行每组测试以及您在代码中进行的任何函数调用的一次。这有助于一些有趣的行为,并且可能会在开始时将您绊倒,因为您希望只看到一次的记录值可能会打印出更多次,具体取决于测试次数和传递给这些测试的值。如果您只想查看单个输出而不必担心运行测试周期,可以使用<code>console.clear()</code> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">使用<code>console.log()</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.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<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
|
||||
|
||||
|
||||
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 outputOne variable
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
id: 587d7b86367417b2b2512b3c
|
||||
title: Use Caution When Reinitializing Variables Inside a Loop
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 在循环内重新初始化变量时请小心
|
||||
---
|
||||
|
||||
## Description
|
||||
<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>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应该将<code>matrix</code>变量设置为一个数组,每个数组包含3行,每列2列零。
|
||||
testString: 'assert(JSON.stringify(matrix) == "[[0,0],[0,0],[0,0]]", "Your code should set the <code>matrix</code> variable to an array holding 3 rows of 2 columns of zeroes each.");'
|
||||
- text: <code>matrix</code>变量应该有3行。
|
||||
testString: 'assert(matrix.length == 3, "The <code>matrix</code> variable should have 3 rows.");'
|
||||
- text: <code>matrix</code>变量每行应有2列。
|
||||
testString: 'assert(matrix[0].length == 2 && matrix[1].length === 2 && matrix[2].length === 2, "The <code>matrix</code> variable should have 2 columns in each row.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function zeroArray(m, n) {
|
||||
// Creates a 2-D array with m rows and n columns of zeroes
|
||||
let newArray = [];
|
||||
let row = [];
|
||||
for (let i = 0; i < m; i++) {
|
||||
// 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);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,56 @@
|
||||
---
|
||||
id: 587d7b83367417b2b2512b33
|
||||
title: Use the JavaScript Console to Check the Value of a Variable
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用JavaScript控制台检查变量的值
|
||||
---
|
||||
|
||||
## 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>
|
||||
|
||||
## Instructions
|
||||
<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>的值。
|
||||
testString: 'assert(code.match(/console\.log\(a\)/g), "Your code should use <code>console.log()</code> to check the value of the variable <code>a</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let a = 5;
|
||||
let b = 1;
|
||||
a++;
|
||||
// Add your code below this line
|
||||
|
||||
|
||||
let sumAB = a + b;
|
||||
console.log(sumAB);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,56 @@
|
||||
---
|
||||
id: 587d7b84367417b2b2512b34
|
||||
title: Use typeof to Check the Type of a Variable
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 使用typeof检查变量的类型
|
||||
---
|
||||
|
||||
## 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>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">添加两个<code>console.log()</code>语句来检查<code>typeof</code>每两个变量的<code>seven</code>和<code>three</code>中的代码。 </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 您的代码应在两个<code>console.log()</code>语句中使用<code>typeof</code>来检查变量的类型。
|
||||
testString: 'assert(code.match(/console\.log\(typeof[\( ].*\)?\)/g).length == 2, "Your code should use <code>typeof</code> in two <code>console.log()</code> statements to check the type of the variables.");'
|
||||
- text: 您的代码应使用<code>typeof</code>来检查变量类型<code>seven</code> 。
|
||||
testString: 'assert(code.match(/typeof[\( ]seven\)?/g), "Your code should use <code>typeof</code> to check the type of the variable <code>seven</code>.");'
|
||||
- text: 您的代码应使用<code>typeof</code>来检查变量的类型<code>three</code> 。
|
||||
testString: 'assert(code.match(/typeof[\( ]three\)?/g), "Your code should use <code>typeof</code> to check the type of the variable <code>three</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let seven = 7;
|
||||
let three = "3";
|
||||
console.log(seven + three);
|
||||
// Add your code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
Reference in New Issue
Block a user