chore(i8n,learn): processed translations

This commit is contained in:
Crowdin Bot
2021-02-06 04:42:36 +00:00
committed by Mrugesh Mohapatra
parent 15047f2d90
commit e5c44a3ae5
3274 changed files with 172122 additions and 14164 deletions

View File

@ -1,6 +1,6 @@
---
id: 587d7b85367417b2b2512b3a
title: 调用函数时,捕获以错误顺序传递的参数
title: Catch Arguments Passed in the Wrong Order When Calling a Function
challengeType: 1
forumTopicId: 301184
dashedName: catch-arguments-passed-in-the-wrong-order-when-calling-a-function
@ -8,21 +8,21 @@ dashedName: catch-arguments-passed-in-the-wrong-order-when-calling-a-function
# --description--
继续讨论调用函数,需要注意的下一个 bug 是函数的参数传递顺序错误。 如果参数分别是不同的类型,例如接受数组和整数两个参数的函数,参数顺序传错就可能会引发运行时错误。对于接受相同类型参数的函数,传错参数也会导致逻辑错误或运行结果错误。确保以正确的顺序提供所有必需的参数以避免这些问题。
Continuing the discussion on calling functions, the next bug to watch out for is when a function's arguments are supplied in the incorrect order. If the arguments are different types, such as a function expecting an array and an integer, this will likely throw a runtime error. If the arguments are the same type (all integers, for example), then the logic of the code won't make sense. Make sure to supply all required arguments, in the proper order to avoid these issues.
# --instructions--
函数`raiseToPower`返回基数 (base) 的指数 (exponent) 次幂。不幸的是,它没有被正确调用 ———— 修改代码,使`power`的值为 8
The function `raiseToPower` raises a base to an exponent. Unfortunately, it's not called properly - fix the code so the value of `power` is the expected 8.
# --hints--
你应修复变量`power`,使其等于 2 的 3 次方,而不是 3 的 2 次方。
Your code should fix the variable `power` so it equals 2 raised to the 3rd power, not 3 raised to the 2nd power.
```js
assert(power == 8);
```
你调用`raiseToPower`函数时,传递参数的顺序应正确。
Your code should use the correct order of the arguments for the `raiseToPower` function call.
```js
assert(code.match(/raiseToPower\(\s*?base\s*?,\s*?exp\s*?\);/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b85367417b2b2512b39
title: 捕捉函数调用后缺少的左括号和右括号
title: Catch Missing Open and Closing Parenthesis After a Function Call
challengeType: 1
forumTopicId: 301185
dashedName: catch-missing-open-and-closing-parenthesis-after-a-function-call
@ -8,9 +8,9 @@ dashedName: catch-missing-open-and-closing-parenthesis-after-a-function-call
# --description--
当函数或方法不接受任何参数时,你可能忘记在调用它时加上空的左括号和右括号。通常,函数调用的结果会保存在变量中,供其他代码使用。可以通过将变量值(或其类型)打印到控制台,查看输出究竟是一个函数引用还是函数调用的返回值来检测这类错误。
When a function or method doesn't take any arguments, you may forget to include the (empty) opening and closing parentheses when calling it. Often times the result of a function call is saved in a variable for other use in your code. This error can be detected by logging variable values (or their types) to the console and seeing that one is set to a function reference, instead of the expected value the function returns.
下面示例中的两个变量是不同的:
The variables in the following example are different:
```js
function myFunction() {
@ -22,17 +22,17 @@ let varTwo = myFunction(); // set to equal the string "You rock!"
# --instructions--
修复代码,把调用函数`getNine`的返回值赋给变量`result`
Fix the code so the variable `result` is set to the value returned from calling the function `getNine`.
# --hints--
你应该修复变量`result`使其为函数`getNine`的返回值。
Your code should fix the variable `result` so it is set to the number that the function `getNine` returns.
```js
assert(result == 9);
```
你应该调用`getNine`函数。
Your code should call the `getNine` function.
```js
assert(code.match(/getNine\(\)/g).length == 2);

View File

@ -1,6 +1,6 @@
---
id: 587d7b84367417b2b2512b35
title: 捕获拼错的变量名和函数名
title: Catch Misspelled Variable and Function Names
challengeType: 1
forumTopicId: 301186
dashedName: catch-misspelled-variable-and-function-names
@ -8,41 +8,41 @@ dashedName: catch-misspelled-variable-and-function-names
# --description--
`console.log()``typeof`方法是检查中间值和程序输出类型的两种主要方法。 现在是时候了解一下 bug 出现的常见的情形。一个语法级别的问题是打字太快带来的低级拼写错误。
The `console.log()` and `typeof` methods are the two primary ways to check intermediate values and types of program output. Now it's time to get into the common forms that bugs take. One syntax-level issue that fast typers can commiserate with is the humble spelling error.
变量或函数名的错写、漏写或大小写弄混都会让浏览器尝试查找并不存在的东西并报出“引用错误”。JavaScript 变量和函数名称区分大小写。
Transposed, missing, or mis-capitalized characters in a variable or function name will have the browser looking for an object that doesn't exist - and complain in the form of a reference error. JavaScript variable and function names are case-sensitive.
# --instructions--
修复代码中的两个拼写错误,以便`netWorkingCapital`计算有效。
Fix the two spelling errors in the code so the `netWorkingCapital` calculation works.
# --hints--
检查计算 netWorkingCapital 值时使用的两个变量的拼写是否正确,控制台应该输出 "Net working capital is: 2"
Check the spelling of the two variables used in the netWorkingCapital calculation, the console output should show that "Net working capital is: 2".
```js
assert(netWorkingCapital === 2);
```
代码中不应存在拼写错误的变量。
There should be no instances of mis-spelled variables in the code.
```js
assert(!code.match(/recievables/g));
```
应在代码中声明并正确使用`receivables`变量。
The `receivables` variable should be declared and used properly in the code.
```js
assert(code.match(/receivables/g).length == 2);
```
代码中不应存在拼写错误的变量。
There should be no instances of mis-spelled variables in the code.
```js
assert(!code.match(/payable;/g));
```
应在代码中声明并正确使用`payables`变量。
The `payables` variable should be declared and used properly in the code.
```js
assert(code.match(/payables/g).length == 2);

View File

@ -1,6 +1,6 @@
---
id: 587d7b84367417b2b2512b37
title: 捕捉单引号和双引号的混合用法
title: Catch Mixed Usage of Single and Double Quotes
challengeType: 1
forumTopicId: 301188
dashedName: catch-mixed-usage-of-single-and-double-quotes
@ -8,11 +8,11 @@ dashedName: catch-mixed-usage-of-single-and-double-quotes
# --description--
JavaScript允许使用单引号('')和双引号("")声明字符串。决定使用哪一个通常看个人偏好,但有一些例外。
JavaScript allows the use of both single (`'`) and double (`"`) quotes to declare a string. Deciding which one to use generally comes down to personal preference, with some exceptions.
如果字符串中有缩写或存在一段带引号的文本,你就会明白为什么 JavaScript 允许两种引号了。请注意,不要提前用引号结束字符串,这会导致语法错误。
Having two choices is great when a string has contractions or another piece of text that's in quotes. Just be careful that you don't close the string too early, which causes a syntax error.
下面是混合使用引号的一些示例:
Here are some examples of mixing quotes:
```js
// These are correct:
@ -22,26 +22,26 @@ const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quot
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
```
当然,只使用一种引号是可以的。你可以使用反斜杠 (`\`) 转义字符来转义字符串中的引号:
Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (<code>\\</code>) escape character:
```js
// 一种引号的正确使用方式
// Correct use of same quotes:
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
```
# --instructions--
修复字符串,对`href`属性的值使用不同的引号,或者转义现有的引号。注意,整个字符串外面的双引号要保留。
Fix the string so it either uses different quotes for the `href` value, or escape the existing ones. Keep the double quote marks around the entire string.
# --hints--
你应通过更改或转义来修复`href`的值 '#Home' 周围的引号。
Your code should fix the quotes around the `href` value "#Home" by either changing or escaping them.
```js
assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
```
你应该在整个字符串外围保留双引号。
Your code should keep the double quotes around the entire string.
```js
assert(code.match(/"<p>.*?<\/p>";/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b86367417b2b2512b3b
title: 捕获使用索引的时候出现的错误
title: Catch Off By One Errors When Using Indexing
challengeType: 1
forumTopicId: 301189
dashedName: catch-off-by-one-errors-when-using-indexing
@ -8,52 +8,52 @@ dashedName: catch-off-by-one-errors-when-using-indexing
# --description--
当试图访问字符串或数组的特定索引(分割或访问一个片段)或循环索引时,有时会出现`Off by one errors`错误(有时称为 OBOE。JavaScript 索引从`0`开始,而不是`1`,这意味着最后一个索引总会比字符串或数组的长度少 1。如果尝试访问等于长度的索引程序可能会抛出“索引超出范围”引用错误或打印出`undefined`
<dfn>Off by one errors</dfn> (sometimes called OBOE) crop up when you're trying to target a specific index of a string or array (to slice or access a segment), or when looping over the indices of them. JavaScript indexing starts at zero, not one, which means the last index is always one less than the length of the item. If you try to access an index equal to the length, the program may throw an "index out of range" reference error or print `undefined`.
当使用将索引范围作为参数的字符串或数组方法时,阅读相关的文档并了解参数中的索引的包含性(即是否考虑进返回值中)很重要。以下是一些错误的示例:
When you use string or array methods that take index ranges as arguments, it helps to read the documentation and understand if they are inclusive (the item at the given index is part of what's returned) or not. Here are some examples of off by one errors:
```js
let alphabet = "abcdefghijklmnopqrstuvwxyz";
let len = alphabet.length;
for (let i = 0; i <= len; i++) {
// 在最后多了一次循环
// loops one too many times at the end
console.log(alphabet[i]);
}
for (let j = 1; j < len; j++) {
// 循环少了一次,漏掉了索引 0 处的字符
// loops one too few times and misses the first character at index 0
console.log(alphabet[j]);
}
for (let k = 0; k < len; k++) {
// 不多不少,这才是正确的
// Goldilocks approves - this is just right
console.log(alphabet[k]);
}
```
# --instructions--
修复以下函数中的两个索引错误,以便将 1 到 5 之间(包含 1 和 5的所有数字打印到控制台。
Fix the two indexing errors in the following function so all the numbers 1 through 5 are printed to the console.
# --hints--
你应该设置循环的初始条件,使循环从第一个索引开始。
Your code should set the initial condition of the loop so it starts at the first index.
```js
assert(code.match(/i\s*?=\s*?0\s*?;/g).length == 1);
```
你应修复循环的初始条件,使循环从索引 0 开始。
Your code should fix the initial condition of the loop so that the index starts at 0.
```js
assert(!code.match(/i\s?=\s*?1\s*?;/g));
```
你应设置循环的终止条件,使循环在最后一个索引处停止。
Your code should set the terminal condition of the loop so it stops at the last index.
```js
assert(code.match(/i\s*?<\s*?len\s*?;/g).length == 1);
```
你应修复循环的终止条件,使循环在索引为字符串长度减 1 时停止。
Your code should fix the terminal condition of the loop so that it stops at 1 before the length.
```js
assert(!code.match(/i\s*?<=\s*?len;/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b84367417b2b2512b36
title: 捕获未闭合的括号、方括号、大括号和引号
title: 'Catch Unclosed Parentheses, Brackets, Braces and Quotes'
challengeType: 1
forumTopicId: 301190
dashedName: catch-unclosed-parentheses-brackets-braces-and-quotes
@ -8,23 +8,23 @@ dashedName: catch-unclosed-parentheses-brackets-braces-and-quotes
# --description--
要注意的另一个语法错误是所有的小括号、方括号、花括号和引号都必须配对。当你编辑代码并插入新代码其中带有括号时,很容易忘记括号闭合。 此外,在将代码块嵌套到其他代码块时要小心,例如将回调函数作为参数添加到方法中。
Another syntax error to be aware of is that all opening parentheses, brackets, curly braces, and quotes have a closing pair. Forgetting a piece tends to happen when you're editing existing code and inserting items with one of the pair types. Also, take care when nesting code blocks into others, such as adding a callback function as an argument to a method.
避免这种错误的一种方法是,一次性输入完这些符号,然后将光标移回它们之间继续编写。好在,现在大部分编辑器都会帮你自动补全。
One way to avoid this mistake is as soon as the opening character is typed, immediately include the closing match, then move the cursor back between them and continue coding. Fortunately, most modern code editors generate the second half of the pair automatically.
# --instructions--
修复代码中的两个符号配对错误。
Fix the two pair errors in the code.
# --hints--
你应该修复数组缺少的部分。
Your code should fix the missing piece of the array.
```js
assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
```
你应该修复`.reduce()`方法缺少的部分。控制台应输出 "Sum of array values is: 6"
Your code should fix the missing piece of the `.reduce()` method. The console output should show that "Sum of array values is: 6".
```js
assert(arraySum === 6);

View File

@ -1,6 +1,6 @@
---
id: 587d7b85367417b2b2512b38
title: 捕获使用赋值运算符而不是相等运算符
title: Catch Use of Assignment Operator Instead of Equality Operator
challengeType: 1
forumTopicId: 301191
dashedName: catch-use-of-assignment-operator-instead-of-equality-operator
@ -8,37 +8,37 @@ dashedName: catch-use-of-assignment-operator-instead-of-equality-operator
# --description--
分支程序,即在满足某些条件时执行不同操作的程序,依赖于 JavaScript 中的`if``else if``else`语句。条件有时采取测试一个结果是否等于一个值的形式。
Branching programs, i.e. ones that do different things if certain conditions are met, rely on `if`, `else if`, and `else` statements in JavaScript. The condition sometimes takes the form of testing whether a result is equal to a value.
这种逻辑可以表述为“如果 x 等于 y ,则......”,听起来像是可以使用`=`(即赋值运算符)。然而,这会导致程序中流程出问题。
This logic is spoken (in English, at least) as "if x equals y, then ..." which can literally translate into code using the `=`, or assignment operator. This leads to unexpected control flow in your program.
如前面的挑战所述JavaScript 中的赋值运算符 (`=`) 是用来为变量名赋值的。并且`==``===`运算符检查相等性(三等号`===`是用来测试是否严格相等的,严格相等的意思是值和类型都必须相同)。
As covered in previous challenges, the assignment operator (`=`) in JavaScript assigns a value to a variable name. And the `==` and `===` operators check for equality (the triple `===` tests for strict equality, meaning both value and type are the same).
下面的代码将`x`赋值为 2表达式`x = y`会在执行后得到`true`。JavaScript 会把大部分的值都视为`true`,除了所谓的 "falsy" 值,即:`false``0``""`(空字符串)、`NaN``undefined` `null`
The code below assigns `x` to be 2, which evaluates as `true`. Almost every value on its own in JavaScript evaluates to `true`, except what are known as the "falsy" values: `false`, `0`, `""` (an empty string), `NaN`, `undefined`, and `null`.
```js
let x = 1;
let y = 2;
if (x = y) {
// 除了 "falsy" 值以外 y 为任意值时这个代码块都将执行
// this code block will run for any value of y (unless y were originally set as a falsy)
} else {
// 按本例用意这个代码块应该执行(但其实不会)。
// this code block is what should run (but won't) in this example
}
```
# --instructions--
修复条件语句,以便程序运行正确的分支,并给`result`赋上正确的值。
Fix the condition so the program runs the right branch, and the appropriate value is assigned to `result`.
# --hints--
你应该修复条件语句,使其判断是否相等,而不是赋值。
Your code should fix the condition so it checks for equality, instead of using assignment.
```js
assert(result == 'Not equal!');
```
条件语句可以使用`==``===`来测试是否相等。
The condition should use either `==` or `===` to test for equality.
```js
assert(code.match(/x\s*?===?\s*?y/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b86367417b2b2512b3d
title: 使用有效的终止条件防止无限循环
title: Prevent Infinite Loops with a Valid Terminal Condition
challengeType: 1
forumTopicId: 301192
dashedName: prevent-infinite-loops-with-a-valid-terminal-condition
@ -8,9 +8,9 @@ dashedName: prevent-infinite-loops-with-a-valid-terminal-condition
# --description--
最后一个话题是可怕的无限循环。当需要程序运行代码块一定次数或满足条件时,循环是很好的工具,但是它们需要终止条件来结束循环。无限循环可能会使浏览器冻结或崩溃,并导致程序执行混乱,没有人想要这样的结果。
The final topic is the dreaded infinite loop. Loops are great tools when you need your program to run a code block a certain number of times or until a condition is met, but they need a terminal condition that ends the looping. Infinite loops are likely to freeze or crash the browser, and cause general program execution mayhem, which no one wants.
在本节的介绍中有一个无限循环的例子——它没有终止条件来摆脱`loopy()`内的`while`循环。不要调用这个函数!
There was an example of an infinite loop in the introduction to this section - it had no terminal condition to break out of the `while` loop inside `loopy()`. Do NOT call this function!
```js
function loopy() {
@ -20,21 +20,21 @@ function loopy() {
}
```
程序员的工作是确保最终达到终止条件,该条件告诉程序何时跳出循环。有一种错误是从终端条件向错误方向递增或递减计数器变量。另一种是在循环代码中意外重置计数器或索引变量,而不是递增或递减它。
It's the programmer's job to ensure that the terminal condition, which tells the program when to break out of the loop code, is eventually reached. One error is incrementing or decrementing a counter variable in the wrong direction from the terminal condition. Another one is accidentally resetting a counter or index variable within the loop code, instead of incrementing or decrementing it.
# --instructions--
`myFunc()`函数包含一个无限循环,因为终止条件`i != 4`永远不会为`false`(并中断循环) -`i`将每次递增 2然后跳过 4因为`i`是从奇数开始递增。在终端条件中输入比较运算符,使循环仅在`i`小于或等于 4 的情况下运行。
The `myFunc()` function contains an infinite loop because the terminal condition `i != 4` will never evaluate to `false` (and break the looping) - `i` will increment by 2 each pass, and jump right over 4 since `i` is odd to start. Fix the comparison operator in the terminal condition so the loop only runs for `i` less than or equal to 4.
# --hints--
你应该在`for`循环的终止条件(中间部分)中更改比较运算符。
Your code should change the comparison operator in the terminal condition (the middle part) of the `for` loop.
```js
assert(code.match(/i\s*?<=\s*?4;/g).length == 1);
```
你应该修改比较运算符来避免出现死循环。
Your code should fix the comparison operator in the terminal condition of the loop.
```js
assert(!code.match(/i\s*?!=\s*?4;/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b83367417b2b2512b37
title: 了解 freeCodeCamp 和浏览器控制台之间的差异
title: Understanding the Differences between the freeCodeCamp and Browser Console
challengeType: 1
forumTopicId: 301193
dashedName: understanding-the-differences-between-the-freecodecamp-and-browser-console
@ -8,37 +8,40 @@ dashedName: understanding-the-differences-between-the-freecodecamp-and-browser-c
# --description--
你可能已经注意到一些 freeCodeCamp JavaScript 的挑战有自己的控制台。这些控制台的行为与上一次挑战中使用的浏览器控制台略有不同。
You may have noticed that some freeCodeCamp JavaScript challenges include their own console. This console behaves a little differently than the browser console you used in the last challenge.
以下挑战旨在强调 freeCodeCamp 控制台与浏览器控制台之间的一些差异。
The following challenge is meant to highlight the main difference between the freeCodeCamp console and your browser console.
对于浏览器控制台。当在浏览器中加载并运行 JavaScript 文件时,`console.log()`语句会在控制台中按照调用的次数准确地打印出要求的内容。然而,在 freeCodeCamp 的代码编辑器中使用`console.log()`会略有不同,一开始可能会让你感到困惑。
When you run ordinary JavaScript, the browser's console will display your `console.log()` statements the exact number of times it is called.
freeCodeCamp 代码编辑器中,传给`console.log()`的值会在每组测试执行的时候输出。另外,如果在代码中还手动调用过挑战题目的函数,调用几次就会增加几次传入值的输出。
The freeCodeCamp console will print your `console.log()` statements a short time after the editor detects a change in the script, as well as during testing.
这就产生了一些有趣的行为,并可能在一开始就让你感到困惑,因为你觉得只会输出一次的值可能会输出多次,具体次数取决于挑战题目本身测试的数量以及这些测试调用挑战函数的方式。
The freeCodeCamp console is cleared before the tests are run and, to avoid spam, only prints the logs during the first test (see the note below for exceptions).
如果你不打算执行挑战的测试,而只想查看自己调用`console.log()`的输出,可以使用`console.clear()`
If you would like to see every log for every test, run the tests, and open the browser console. If you prefer to use the browser console, and want it to mimic the freeCodeCamp console, place `console.clear()` before any other `console` calls, to clear the browser console.
**Note:** `console.log`s inside functions are printed to the freeCodeCamp console whenever those functions are called, this can help debugging functions that are called during testing.
# --instructions--
首先,使用 `console.clear()` 清空浏览器控制台。然后使用`console.log()`在代码中指定的位置打印 `output` 变量。
First, use `console.log` to log the `output` variable. Then, use `console.clear` to clear the browser console.
# --hints--
应该使用 `console.clear()` 来清空浏览器控制台。
You should use `console.clear()` to clear the browser console.
```js
const removeJSComments = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
const noSpaces = removeJSComments.replace(/\s/g, '');
assert(noSpaces.match(/console.clear\(\)/));
assert(
__helpers
.removeWhiteSpace(__helpers.removeJSComments(code))
.match(/console.clear\(\)/)
);
```
使用`console.log()`输出变量`output`的值。
You should use `console.log()` to print the `output` variable.
```js
const noSpaces = code.replace(/\s/g, '');
assert(noSpaces.match(/console\.log\(output\)/));
assert(__helpers.removeWhiteSpace(code).match(/console\.log\(output\)/));
```
# --seed--

View File

@ -1,6 +1,6 @@
---
id: 587d7b86367417b2b2512b3c
title: 重新初始化循环中的变量时要小心
title: Use Caution When Reinitializing Variables Inside a Loop
challengeType: 1
forumTopicId: 301194
dashedName: use-caution-when-reinitializing-variables-inside-a-loop
@ -8,29 +8,29 @@ dashedName: use-caution-when-reinitializing-variables-inside-a-loop
# --description--
有时需要在循环中保存信息以增加计数器或重置变量。一个潜在的问题是变量什么时候该重新初始化,什么时候不该重新初始化,反之亦然。如果你不小心重置了用于终止条件的变量,导致无限循环,这将特别危险。
Sometimes it's necessary to save information, increment counters, or re-set variables within a loop. A potential issue is when variables either should be reinitialized, and aren't, or vice versa. This is particularly dangerous if you accidentally reset the variable being used for the terminal condition, causing an infinite loop.
使用`console.log()`在每个循环中打印变量值可以发现与重置相关的错误或者重置变量失败。
Printing variable values with each cycle of your loop by using `console.log()` can uncover buggy behavior related to resetting, or failing to reset a variable.
# --instructions--
以下函数应该创建一个具有`m`行和`n`列“零”的二维数组。不幸的是,它没有产生预期的输出,因为`row`变量没有在外部循环中重新初始化(设置回空数组)。修改代码,使其正确地返回包含 3 行 2 列“零”的二维数组,即`[[0, 0], [0, 0], [0, 0]]`
The following function is supposed to create a two-dimensional array with `m` rows and `n` columns of zeroes. Unfortunately, it's not producing the expected output because the `row` variable isn't being reinitialized (set back to an empty array) in the outer loop. Fix the code so it returns a correct 3x2 array of zeroes, which looks like `[[0, 0], [0, 0], [0, 0]]`.
# --hints--
你应将变量`matrix`设置为 3 行 2 列“零”的二维数组。
Your code should set the `matrix` variable to an array holding 3 rows of 2 columns of zeroes each.
```js
assert(JSON.stringify(matrix) == '[[0,0],[0,0],[0,0]]');
```
变量`matrix`应有 3 行。
The `matrix` variable should have 3 rows.
```js
assert(matrix.length == 3);
```
变量`matrix`每行应有 2 列。
The `matrix` variable should have 2 columns in each row.
```js
assert(

View File

@ -1,6 +1,6 @@
---
id: 587d7b83367417b2b2512b33
title: 使用控制台检查变量值
title: Use the JavaScript Console to Check the Value of a Variable
challengeType: 1
forumTopicId: 18372
dashedName: use-the-javascript-console-to-check-the-value-of-a-variable
@ -8,23 +8,23 @@ dashedName: use-the-javascript-console-to-check-the-value-of-a-variable
# --description--
Chrome Firefox 都有出色的 JavaScript 控制台(也称为 DevTools可以用来调试 JavaScript 代码
Both Chrome and Firefox have excellent JavaScript consoles, also known as DevTools, for debugging your JavaScript.
可以在 Chrome 的菜单中找到“开发者工具”或 FireFox 的菜单中的 “Web 控制台”。如果你使用其他浏览器或手机,我们强烈建议你切换到桌面版 Firefox Chrome
You can find Developer tools in your Chrome's menu or Web Console in Firefox's menu. If you're using a different browser, or a mobile phone, we strongly recommend switching to desktop Firefox or Chrome.
`console.log()`方法可能是最有用的调试工具,它可以将括号中的内容输出到控制台,将它放在代码中的关键点可以显示变量在当时的值。在查看输出之前,最好先想清楚输出应该是什么。在代码的合适位置打点来查看变量状态有助于定位问题。
The `console.log()` method, which "prints" the output of what's within its parentheses to the console, will likely be the most helpful debugging tool. Placing it at strategic points in your code can show you the intermediate values of variables. It's good practice to have an idea of what the output should be before looking at what it is. Having check points to see the status of your calculations throughout your code will help narrow down where the problem is.
下面是输出 'Hello world!' 到控制台的示例:
Here's an example to print 'Hello world!' to the console:
`console.log('Hello world!');`
# --instructions--
请使用`console.log()`方法在代码中注明的地方输出变量`a`的值。
Use the `console.log()` method to print the value of the variable `a` where noted in the code.
# --hints--
你应使用`console.log()`来检查变量`a`的值。
Your code should use `console.log()` to check the value of the variable `a`.
```js
assert(code.match(/console\.log\(a\)/g));

View File

@ -1,6 +1,6 @@
---
id: 587d7b84367417b2b2512b34
title: 使用 type of 检查变量的类型
title: Use typeof to Check the Type of a Variable
challengeType: 1
forumTopicId: 18374
dashedName: use-typeof-to-check-the-type-of-a-variable
@ -8,38 +8,38 @@ dashedName: use-typeof-to-check-the-type-of-a-variable
# --description--
可以使用`typeof`检查变量的数据结构或类型。在处理多种数据类型时,`typeof`会对调试很有帮助。如果想计算两数之和,但实际传入了一个字符串参数,则结果可能是错误的。类型错误可能隐藏在计算或函数调用中。当你以 JavaScript 对象JSON的形式访问和使用外部数据时尤其要小心。
You can use `typeof` to check the data structure, or type, of a variable. This is useful in debugging when working with multiple data types. If you think you're adding two numbers, but one is actually a string, the results can be unexpected. Type errors can lurk in calculations or function calls. Be careful especially when you're accessing and working with external data in the form of a JavaScript Object Notation (JSON) object.
下面是使用`typeof`的一些示例:
Here are some examples using `typeof`:
```js
console.log(typeof ""); // 输出 "string"
console.log(typeof 0); // 输出 "number"
console.log(typeof []); // 输出 "object"
console.log(typeof {}); // 输出 "object"
console.log(typeof ""); // outputs "string"
console.log(typeof 0); // outputs "number"
console.log(typeof []); // outputs "object"
console.log(typeof {}); // outputs "object"
```
JavaScript 有六种原始(不可变)数据类型:`Boolean`,`Null`,`Undefined`,`Number`,`String`, `Symbol`ES6 新增)和一种可变的数据类型:`Object`。注意,在 JavaScript 中,数组在本质上是一种对象
JavaScript recognizes six primitive (immutable) data types: `Boolean`, `Null`, `Undefined`, `Number`, `String`, and `Symbol` (new with ES6) and one type for mutable items: `Object`. Note that in JavaScript, arrays are technically a type of object.
# --instructions--
添加两个`console.log()`语句来检查代码中的两个变量`seven``three``typeof`值。
Add two `console.log()` statements to check the `typeof` each of the two variables `seven` and `three` in the code.
# --hints--
你应在两个`console.log()`语句中使用`typeof`来检查变量的类型。
Your code should use `typeof` in two `console.log()` statements to check the type of the variables.
```js
assert(code.match(/console\.log\(typeof[\( ].*\)?\)/g).length == 2);
```
你应使用`typeof`来检查变量`seven`的类型。
Your code should use `typeof` to check the type of the variable `seven`.
```js
assert(code.match(/typeof[\( ]seven\)?/g));
```
你应使用`typeof`来检查变量`three`的类型。
Your code should use `typeof` to check the type of the variable `three`.
```js
assert(code.match(/typeof[\( ]three\)?/g));