diff --git a/02-javascript-algorithms-and-data-structures/basic-javascript.json b/02-javascript-algorithms-and-data-structures/basic-javascript.json
index 41de1c6..2663bb0 100644
--- a/02-javascript-algorithms-and-data-structures/basic-javascript.json
+++ b/02-javascript-algorithms-and-data-structures/basic-javascript.json
@@ -8,27 +8,27 @@
"id": "bd7123c9c441eddfaeb4bdef",
"title": "Comment Your JavaScript Code",
"description": [
- "Comments are lines of code that JavaScript will intentionally ignore. Comments are a great way to leave notes to yourself and to other people who will later need to figure out what that code does.",
- "There are two ways to write comments in JavaScript:",
- "Using //
will tell JavaScript to ignore the remainder of the text on the current line:",
- "
// This is an in-line comment.
",
- "You can make a multi-line comment beginning with /*
and ending with */
:",
- "/* This is a
multi-line comment */
",
- "Best Practice
As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others and for your future self.",
+ "被注释的代码块在 JavaScript 之中是不会执行的。注释是一个非常好的方式让你自己以及其他人明白这段代码是怎么执行的。",
+ "JavaScript 中的注释方式有以下两种:",
+ "使用//
来告诉 JavaScript 来忽略当前行的代码",
+ "// 这是一条单行注释。
",
+ "你也可以使用多行注释来注释你的代码,以/*
开始,用*/
来结束,就像下面这样:",
+ "/* 这是一个
多行注释 */
",
+ "最佳实践
给你写的代码添加注释,让你的代码看起来更加清晰易懂。良好的注释能够清晰地传达你写代码的意图——无论是别人看你的代码还是以后你自己再看的时候。",
"
",
- "Try creating one of each type of comment."
+ "尝试创建这两种类型的注释。"
],
"solutions": [
"// Fake Comment\n/* Another Comment */"
],
"tests": [
{
- "text": "Create a //
style comment that contains at least five letters.",
- "testString": "assert(code.match(/(\\/\\/)...../g), 'Create a //
style comment that contains at least five letters.');"
+ "text": "创建一个//
样式的注释, 被注释的文本至少要包含 5 个字符。",
+ "testString": "assert(code.match(/(\\/\\/)...../g), '创建一个//
样式的注释, 被注释的文本至少要包含 5 个字符。');"
},
{
- "text": "Create a /* */
style comment that contains at least five letters.",
- "testString": "assert(code.match(/(\\/\\*)([^\\/]{5,})(?=\\*\\/)/gm), 'Create a /* */
style comment that contains at least five letters.');"
+ "text": "创建一个/* */
样式的注释, 被注释的文本至少要包含 5 个字符。",
+ "testString": "assert(code.match(/(\\/\\*)([^\\/]{5,})(?=\\*\\/)/gm), '创建一个/* */
样式的注释, 被注释的文本至少要包含 5 个字符。');"
}
],
"challengeType": 1,
@@ -47,25 +47,25 @@
"id": "bd7123c9c443eddfaeb5bdef",
"title": "Declare JavaScript Variables",
"description": [
- "In computer science, data is anything that is meaningful to the computer. JavaScript provides seven different data types which are undefined
, null
, boolean
, string
, symbol
, number
, and object
.",
- "For example, computers distinguish between numbers, such as the number 12
, and strings
, such as \"12\"
, \"dog\"
, or \"123 cats\"
, which are collections of characters. Computers can perform mathematical operations on a number, but not on a string.",
- "Variables allow computers to store and manipulate data in a dynamic fashion. They do this by using a \"label\" to point to the data rather than using the data itself. Any of the seven data types may be stored in a variable.",
- "Variables
are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. Computer variables
differ from mathematical variables in that they can store different values at different times.",
- "We tell JavaScript to create or declare a variable by putting the keyword var
in front of it, like so:",
+ "在计算机科学中,data
(数据)就是一切,它对于计算机意义重大。JavaScript 提供七种不同的data types(数据类型),它们是undefined
(未定义), null
(空),boolean
(布尔型),string
(字符串),symbol
(符号),number
(数字),和object
(对象)。",
+ "例如,计算机区分数字(例如数字12
)和字符集合的字符串strings
(例如\"12\"
,\"dog\"
或\"123 cats\"
)。计算机可以对数字执行数学运算,但不能对字符串执行数学运算。",
+ "Variables
(变量)允许计算机以一种动态的形式来存储和操作数据,通过操作指向数据的指针而不是数据本身来避免了内存泄露,以上的七种数据类型都可以存储到一个变量(variable)中。",
+ "Variables
非常类似于你在数学中使用的 x,y 变量,都是以一个简单命名的名称来代替我们赋值给它的数据。计算机中的variables
(变量)与数学中的变量不同的是,计算机可以在不同的时间存储不同类型的变量。",
+ "通过在变量的前面使用关键字var
,声明一个变量,例如:",
"var ourName;
",
- "creates a variable
called ourName
. In JavaScript we end statements with semicolons.",
- "Variable
names can be made up of numbers, letters, and $
or _
, but may not contain spaces or start with a number.",
+ "上面代码的意思是创建一个名为ourName
的variable
(变量),在 JavaScript 中我们以分号结束语句。",
+ "Variable
(变量)名称可以由数字、字母、$
或者 _
组成,但是不能包含空格或者以数字为开头。",
"
",
- "Use the var
keyword to create a variable called myName
.",
- "Hint
Look at the ourName
example if you get stuck."
+ "使用var
关键字来创建一个名为myName
的变量。",
+ "提示
如果遇到困难了,请看下ourName
的例子是怎么写的。"
],
"solutions": [
"var myName;"
],
"tests": [
{
- "text": "You should declare myName
with the var
keyword, ending with a semicolon",
- "testString": "assert(/var\\s+myName\\s*;/.test(code), 'You should declare myName
with the var
keyword, ending with a semicolon');"
+ "text": "你需要使用var
关键字定义一个变量myName
,并使用分号结尾。",
+ "testString": "assert(/var\\s+myName\\s*;/.test(code), '你需要使用var
关键字定义一个变量myName
。并使用分号结尾。');"
}
],
"challengeType": 1,
@@ -75,10 +75,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 举例",
"var ourName;",
"",
- "// Declare myName below this line",
+ "// 请在这条注释以下定义 myName 变量",
""
],
"head": [],
@@ -92,15 +92,15 @@
"id": "56533eb9ac21ba0edf2244a8",
"title": "Storing Values with the Assignment Operator",
"description": [
- "In JavaScript, you can store a value in a variable with the assignment operator.",
+ "在 JavaScript 中,你可以使用赋值运算符将值存储在变量中。",
"myVariable = 5;
",
- "This assigns the Number
value 5
to myVariable
.",
- "Assignment always goes from right to left. Everything to the right of the =
operator is resolved before the value is assigned to the variable to the left of the operator.",
+ "这条语句把Number
值5
赋给变量myVariable
。",
+ "赋值过程是从右到左进行的。在将值分配给运算符左侧的变量之前,将解析=
运算符右侧的所有内容。",
"myVar = 5;
myNum = myVar;
",
- "This assigns 5
to myVar
and then resolves myVar
to 5
again and assigns it to myNum
.",
+ "数值5
被赋给变量myVar
中,然后再次将变量myVar
解析为 5 并将其赋给myNum
变量。",
"
",
- "Assign the value 7
to variable a
.",
- "Assign the contents of a
to variable b
."
+ "把数值7
赋给变量 a
。",
+ "把变量a
中的内容赋给变量b
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -108,20 +108,20 @@
],
"tests": [
{
- "text": "Do not change code above the line",
- "testString": "assert(/var a;/.test(code) && /var b = 2;/.test(code), 'Do not change code above the line');"
+ "text": "不要修改注释上方的代码",
+ "testString": "assert(/var a;/.test(code) && /var b = 2;/.test(code), '不要修改注释上方的代码');"
},
{
- "text": "a
should have a value of 7",
- "testString": "assert(typeof a === 'number' && a === 7, 'a
should have a value of 7');"
+ "text": "a
的值应该是 7",
+ "testString": "assert(typeof a === 'number' && a === 7, 'a
的值应该是 7');"
},
{
- "text": "b
should have a value of 7",
- "testString": "assert(typeof b === 'number' && b === 7, 'b
should have a value of 7');"
+ "text": "b
的值应该是 7",
+ "testString": "assert(typeof b === 'number' && b === 7, 'b
的值应该是 7');"
},
{
- "text": "a
should be assigned to b
with =
",
- "testString": "assert(/b\\s*=\\s*a\\s*;/g.test(code), 'a
should be assigned to b
with =
');"
+ "text": "你需要用=
把a
的值赋给b
",
+ "testString": "assert(/b\\s*=\\s*a\\s*;/g.test(code), '你需要用=
把a
的值赋给b
');"
}
],
"challengeType": 1,
@@ -131,11 +131,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 举例",
"var a;",
"var b = 2;",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
""
],
"head": [
@@ -156,11 +156,11 @@
"id": "56533eb9ac21ba0edf2244a9",
"title": "Initializing Variables with the Assignment Operator",
"description": [
- "It is common to initialize a variable to an initial value in the same line as it is declared.",
+ "通常地我们会在initialize开始声明变量的时候就会给变量赋一个初始值。",
"var myVar = 0;
",
- "Creates a new variable called myVar
and assigns it an initial value of 0
.",
+ "创建一个名为myVar
的变量并指定一个初始值0
。",
"
",
- "Define a variable a
with var
and initialize it to a value of 9
."
+ "通过关键字var
定义一个变量a
并且给它一个初始值9
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -168,8 +168,8 @@
],
"tests": [
{
- "text": "Initialize a
to a value of 9
",
- "testString": "assert(/var\\s+a\\s*=\\s*9\\s*/.test(code), 'Initialize a
to a value of 9
');"
+ "text": "你需要初始化a
的值为9
",
+ "testString": "assert(/var\\s+a\\s*=\\s*9\\s*/.test(code), '你需要初始化a
的值为9
');"
}
],
"challengeType": 1,
@@ -179,10 +179,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 举例",
"var ourVar = 19;",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
""
],
"head": [],
@@ -196,9 +196,9 @@
"id": "56533eb9ac21ba0edf2244aa",
"title": "Understanding Uninitialized Variables",
"description": [
- "When JavaScript variables are declared, they have an initial value of undefined
. If you do a mathematical operation on an undefined
variable your result will be NaN
which means \"Not a Number\". If you concatenate a string with an undefined
variable, you will get a literal string of \"undefined\"
.",
+ "当 JavaScript 中的变量被声明的时候,程序内部会给它一个初始值undefined
。当你对一个值为undefined
的变量进行运算操作的时候,算出来的结果将会是NaN
,NaN
的意思是\"Not a Number\"。当你用一个值是undefined
的变量来做字符串拼接操作的时候,它会输出字符串\"undefined\"
。",
"
",
- "Initialize the three variables a
, b
, and c
with 5
, 10
, and \"I am a\"
respectively so that they will not be undefined
."
+ "定义 3 个变量a
、b
、c
,并且分别给他们赋值:5
、10
、\"I am a\"
,这样它们值就不会是undefined
了。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -206,20 +206,20 @@
],
"tests": [
{
- "text": "a
should be defined and evaluated to have the value of 6
",
- "testString": "assert(typeof a === 'number' && a === 6, 'a
should be defined and evaluated to have the value of 6
');"
+ "text": "a
应该被定义,并且值为6
",
+ "testString": "assert(typeof a === 'number' && a === 6, 'a
应该被定义,并且值为6
');"
},
{
- "text": "b
should be defined and evaluated to have the value of 15
",
- "testString": "assert(typeof b === 'number' && b === 15, 'b
should be defined and evaluated to have the value of 15
');"
+ "text": "a
应该被定义,并且值为15
",
+ "testString": "assert(typeof b === 'number' && b === 15, 'a
应该被定义,并且值为15
');"
},
{
- "text": "c
should not contain undefined
and should have a value of \"I am a String!\"",
- "testString": "assert(!/undefined/.test(c) && c === \"I am a String!\", 'c
should not contain undefined
and should have a value of \"I am a String!\"');"
+ "text": "c
的值不能包含undefined
,应该为 \"I am a String!\"",
+ "testString": "assert(!/undefined/.test(c) && c === \"I am a String!\", 'c
的值不能包含undefined
,应该为 \"I am a String!\"');"
},
{
- "text": "Do not change code below the line",
- "testString": "assert(/a = a \\+ 1;/.test(code) && /b = b \\+ 5;/.test(code) && /c = c \\+ \" String!\";/.test(code), 'Do not change code below the line');"
+ "text": "不要修改第二条注释下的代码",
+ "testString": "assert(/a = a \\+ 1;/.test(code) && /b = b \\+ 5;/.test(code) && /c = c \\+ \" String!\";/.test(code), '不要修改第二条注释下的代码');"
}
],
"challengeType": 1,
@@ -229,12 +229,12 @@
"ext": "js",
"name": "index",
"contents": [
- "// Initialize these three variables",
+ "// 初始化变量",
"var a;",
"var b;",
"var c;",
"",
- "// Do not change code below this line",
+ "// 请只修改这条注释以上的代码",
"",
"a = a + 1;",
"b = b + 5;",
@@ -252,14 +252,14 @@
"id": "56533eb9ac21ba0edf2244ab",
"title": "Understanding Case Sensitivity in Variables",
"description": [
- "In JavaScript all variables and function names are case sensitive. This means that capitalization matters.",
- "MYVAR
is not the same as MyVar
nor myvar
. It is possible to have multiple distinct variables with the same name but different casing. It is strongly recommended that for the sake of clarity, you do not use this language feature.",
- "Best Practice
",
- "Write variable names in JavaScript in camelCase. In camelCase, multi-word variable names have the first word in lowercase and the first letter of each subsequent word is capitalized.",
- "Examples:",
- "var someVariable;
var anotherVariableName;
var thisVariableNameIsSoLong;
",
+ "在 JavaScript 中所有的变量和函数名都是大小写敏感的。要区别对待大写字母和小写字母。",
+ "MYVAR
与MyVar
和myvar
是截然不同的变量。这就有可能导致多个截然不同的变量却有着有相似的名字。正是由于以上原因所以强烈地建议你,不要使用这一特性。(以免给自己带来麻烦)",
+ "最佳实践
",
+ "使用驼峰命名法来书写一个 Javascript 变量,在驼峰命名法中,变量名的第一个单词的首写字母小写,后面的单词的第一个字母大写。",
+ "示例:",
+ "var someVariable;
var anotherVariableName;
var thisVariableNameIsTooLong;
",
"
",
- "Modify the existing declarations and assignments so their names use camelCase.
Do not create any new variables."
+ "修改已声明的变量,让它们的命名符合驼峰命名法的规范。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -267,28 +267,28 @@
],
"tests": [
{
- "text": "studlyCapVar
is defined and has a value of 10
",
- "testString": "assert(typeof studlyCapVar !== 'undefined' && studlyCapVar === 10, 'studlyCapVar
is defined and has a value of 10
');"
+ "text": "studlyCapVar
应该被定义并且值为10
",
+ "testString": "assert(typeof studlyCapVar !== 'undefined' && studlyCapVar === 10, 'studlyCapVar
应该被定义并且值为10
');"
},
{
- "text": "properCamelCase
is defined and has a value of \"A String\"
",
- "testString": "assert(typeof properCamelCase !== 'undefined' && properCamelCase === \"A String\", 'properCamelCase
is defined and has a value of \"A String\"
');"
+ "text": "properCamelCase
应该被定义并且值为\"A String\"
",
+ "testString": "assert(typeof properCamelCase !== 'undefined' && properCamelCase === \"A String\", 'properCamelCase
应该被定义并且值为\"A String\"
');"
},
{
- "text": "titleCaseOver
is defined and has a value of 9000
",
- "testString": "assert(typeof titleCaseOver !== 'undefined' && titleCaseOver === 9000, 'titleCaseOver
is defined and has a value of 9000
');"
+ "text": "titleCaseOver
应该被定义并且值为9000
",
+ "testString": "assert(typeof titleCaseOver !== 'undefined' && titleCaseOver === 9000, 'titleCaseOver
应该被定义并且值为9000
');"
},
{
- "text": "studlyCapVar
should use camelCase in both declaration and assignment sections.",
- "testString": "assert(code.match(/studlyCapVar/g).length === 2, 'studlyCapVar
should use camelCase in both declaration and assignment sections.');"
+ "text": "studlyCapVar
在声明和赋值时都应该使用驼峰命名法。",
+ "testString": "assert(code.match(/studlyCapVar/g).length === 2, 'studlyCapVar
在声明和赋值时都应该使用驼峰命名法。');"
},
{
- "text": "properCamelCase
should use camelCase in both declaration and assignment sections.",
- "testString": "assert(code.match(/properCamelCase/g).length === 2, 'properCamelCase
should use camelCase in both declaration and assignment sections.');"
+ "text": "properCamelCase
在声明和赋值时都应该使用驼峰命名法。",
+ "testString": "assert(code.match(/properCamelCase/g).length === 2, 'properCamelCase
在声明和赋值时都应该使用驼峰命名法。');"
},
{
- "text": "titleCaseOver
should use camelCase in both declaration and assignment sections.",
- "testString": "assert(code.match(/titleCaseOver/g).length === 2, 'titleCaseOver
should use camelCase in both declaration and assignment sections.');"
+ "text": "titleCaseOver
在声明和赋值时都应该使用驼峰命名法。",
+ "testString": "assert(code.match(/titleCaseOver/g).length === 2, 'titleCaseOver
在声明和赋值时都应该使用驼峰命名法。');"
}
],
"challengeType": 1,
@@ -298,12 +298,12 @@
"ext": "js",
"name": "index",
"contents": [
- "// Declarations",
+ "// 初始化变量",
"var StUdLyCapVaR;",
"var properCamelCase;",
"var TitleCaseOver;",
"",
- "// Assignments",
+ "// 给变量赋值",
"STUDLYCAPVAR = 10;",
"PRoperCAmelCAse = \"A String\";",
"tITLEcASEoVER = 9000;"
@@ -317,25 +317,25 @@
"id": "cf1111c1c11feddfaeb3bdef",
"title": "Add Two Numbers with JavaScript",
"description": [
- "Number
is a data type in JavaScript which represents numeric data.",
- "Now let's try to add two numbers using JavaScript.",
- "JavaScript uses the +
symbol as addition operation when placed between two numbers.",
- "Example",
+ "Number
是 JavaScript 中的数据类型,表示数值。",
+ "现在让我们来尝试在 JavaScript 中做加法运算。",
+ "JavaScript 中使用+
号来让两个数字执行加法运算。",
+ "示例",
"myVar = 5 + 10; // assigned 15
",
"
",
- "Change the 0
so that sum will equal 20
."
+ "改变数字0
让变量 sum 的值为20
。"
],
"solutions": [
"var sum = 10 + 10;"
],
"tests": [
{
- "text": "sum
should equal 20
",
- "testString": "assert(sum === 20, 'sum
should equal 20
');"
+ "text": "sum
应该等于20
",
+ "testString": "assert(sum === 20, 'sum
应该等于20
');"
},
{
- "text": "Use the +
operator",
- "testString": "assert(/\\+/.test(code), 'Use the +
operator');"
+ "text": "要使用+
运算符",
+ "testString": "assert(/\\+/.test(code), '要使用+
运算符');"
}
],
"challengeType": 1,
@@ -359,26 +359,26 @@
"id": "cf1111c1c11feddfaeb4bdef",
"title": "Subtract One Number from Another with JavaScript",
"description": [
- "We can also subtract one number from another.",
- "JavaScript uses the -
symbol for subtraction.",
+ "我们也可以在 JavaScript 中执行减法运算。",
+ "JavaScript 中使用-
来做减法运算。",
"",
- "Example",
- "myVar = 12 - 6; // assigned 6
",
+ "示例",
+ "myVar = 12 - 6; // 等于 6
",
"",
"
",
- "Change the 0
so the difference is 12
."
+ "改变数字0
让变量 difference 的值为12
。"
],
"solutions": [
"var difference = 45 - 33;"
],
"tests": [
{
- "text": "Make the variable difference
equal 12.",
- "testString": "assert(difference === 12, 'Make the variable difference
equal 12.');"
+ "text": "要使difference
的值等于 12。",
+ "testString": "assert(difference === 12, '要使difference
的值等于 12。');"
},
{
- "text": "Only subtract one number from 45.",
- "testString": "assert(/var\\s*difference\\s*=\\s*45\\s*-\\s*[0-9]*;(?!\\s*[a-zA-Z0-9]+)/.test(code),'Only subtract one number from 45.');"
+ "text": "只用 45 减去一个数。",
+ "testString": "assert(/var\\s*difference\\s*=\\s*45\\s*-\\s*[0-9]*;(?!\\s*[a-zA-Z0-9]+)/.test(code),'只用 45 减去一个数。');"
}
],
"challengeType": 1,
@@ -403,26 +403,26 @@
"id": "cf1231c1c11feddfaeb5bdef",
"title": "Multiply Two Numbers with JavaScript",
"description": [
- "We can also multiply one number by another.",
- "JavaScript uses the *
symbol for multiplication of two numbers.",
+ "我们也可在 JavaScript 中使用乘法运算。",
+ "JavaScript 使用*
符号表示两数相乘。",
"",
- "Example",
- "myVar = 13 * 13; // assigned 169
",
+ "示例",
+ "myVar = 13 * 13; // 把 169 赋值给 myVar
",
"",
"
",
- "Change the 0
so that product will equal 80
."
+ "改变数值0
来让变量 product 的值等于80
。"
],
"solutions": [
"var product = 8 * 10;"
],
"tests": [
{
- "text": "Make the variable product
equal 80",
- "testString": "assert(product === 80,'Make the variable product
equal 80');"
+ "text": "要使product
的值等于 80",
+ "testString": "assert(product === 80,'要使product
的值等于 80');"
},
{
"text": "Use the *
operator",
- "testString": "assert(/\\*/.test(code), 'Use the *
operator');"
+ "testString": "assert(/\\*/.test(code), '使用*
运算符');"
}
],
"challengeType": 1,
@@ -447,26 +447,26 @@
"id": "cf1111c1c11feddfaeb6bdef",
"title": "Divide One Number by Another with JavaScript",
"description": [
- "We can also divide one number by another.",
- "JavaScript uses the /
symbol for division.",
+ "我们可以在 JavaScript 中做除法运算。",
+ "JavaScript 中使用/
符号做除法运算。",
"",
- "Example",
- "myVar = 16 / 2; // assigned 8
",
+ "示例",
+ "myVar = 16 / 2; // 把 8 赋值给 myVar
",
"",
"
",
- "Change the 0
so that the quotient
is equal to 2
."
+ "改变数值0
来让变量quotient
的值等于2
。"
],
"solutions": [
"var quotient = 66 / 33;"
],
"tests": [
{
- "text": "Make the variable quotient
equal to 2.",
- "testString": "assert(quotient === 2, 'Make the variable quotient
equal to 2.');"
+ "text": "要使quotient
的值等于 2。",
+ "testString": "assert(quotient === 2, '要使quotient
的值等于 2。');"
},
{
- "text": "Use the /
operator",
- "testString": "assert(/\\d+\\s*\\/\\s*\\d+/.test(code), 'Use the /
operator');"
+ "text": "使用/
运算符。",
+ "testString": "assert(/\\d+\\s*\\/\\s*\\d+/.test(code), '使用/
运算符。');"
}
],
"challengeType": 1,
@@ -491,14 +491,14 @@
"id": "56533eb9ac21ba0edf2244ac",
"title": "Increment a Number with JavaScript",
"description": [
- "You can easily increment or add one to a variable with the ++
operator.",
+ "使用++
,我们可以很容易地对变量进行自增或者+1
运算。",
"i++;
",
- "is the equivalent of",
+ "等效于",
"i = i + 1;
",
- "Note
The entire line becomes i++;
, eliminating the need for the equal sign.",
+ "注意
i++;
这种写法,省去了书写 = 符号的必要。",
"
",
- "Change the code to use the ++
operator on myVar
.",
- "Hint
Learn more about Arithmetic operators - Increment (++)."
+ "重写代码,使用++
来对变量myVar
进行自增操作。",
+ "提示
了解更多关于Arithmetic operators - Increment (++)."
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -506,20 +506,20 @@
],
"tests": [
{
- "text": "myVar
should equal 88
",
- "testString": "assert(myVar === 88, 'myVar
should equal 88
');"
+ "text": "myVar
应该等于88
",
+ "testString": "assert(myVar === 88, 'myVar
应该等于88
');"
},
{
- "text": "myVar = myVar + 1;
should be changed",
- "testString": "assert(/var\\s*myVar\\s*=\\s*87;\\s*\\/*.*\\s*myVar\\+\\+;/.test(code), 'myVar = myVar + 1;
should be changed');"
+ "text": "myVar = myVar + 1;
语句应该被修改",
+ "testString": "assert(/var\\s*myVar\\s*=\\s*87;\\s*\\/*.*\\s*myVar\\+\\+;/.test(code), 'myVar = myVar + 1;
语句应该被修改');"
},
{
- "text": "Use the ++
operator",
- "testString": "assert(/[+]{2}\\s*myVar|myVar\\s*[+]{2}/.test(code), 'Use the ++
operator');"
+ "text": "使用++
运算符",
+ "testString": "assert(/[+]{2}\\s*myVar|myVar\\s*[+]{2}/.test(code), '使用++
运算符');"
},
{
- "text": "Do not change code above the line",
- "testString": "assert(/var myVar = 87;/.test(code), 'Do not change code above the line');"
+ "text": "不要修改注释上方的代码",
+ "testString": "assert(/var myVar = 87;/.test(code), '不要修改注释上方的代码');"
}
],
"challengeType": 1,
@@ -531,7 +531,7 @@
"contents": [
"var myVar = 87;",
"",
- "// Only change code below this line",
+ "// 请只修改这条注释以下的代码",
"myVar = myVar + 1;",
""
],
@@ -546,13 +546,13 @@
"id": "56533eb9ac21ba0edf2244ad",
"title": "Decrement a Number with JavaScript",
"description": [
- "You can easily decrement or decrease a variable by one with the --
operator.",
+ "使用自减符号--
,你可以很方便地对一个变量执行自减或者减 1 操作。",
"i--;
",
- "is the equivalent of",
+ "等效于",
"i = i - 1;
",
- "Note
The entire line becomes i--;
, eliminating the need for the equal sign.",
+ "提示
i--;
这种写法,省去了书写等号的必要。",
"
",
- "Change the code to use the --
operator on myVar
."
+ "重写代码,使用--
符号对myVar
执行自减操作。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -560,20 +560,20 @@
],
"tests": [
{
- "text": "myVar
should equal 10
",
- "testString": "assert(myVar === 10, 'myVar
should equal 10
');"
+ "text": "myVar
应该等于10
",
+ "testString": "assert(myVar === 10, 'myVar
应该等于10
');"
},
{
- "text": "myVar = myVar - 1;
should be changed",
- "testString": "assert(/var\\s*myVar\\s*=\\s*11;\\s*\\/*.*\\s*myVar--;/.test(code), 'myVar = myVar - 1;
should be changed');"
+ "text": "myVar = myVar - 1;
语句应该被修改",
+ "testString": "assert(/var\\s*myVar\\s*=\\s*11;\\s*\\/*.*\\s*myVar--;/.test(code), 'myVar = myVar - 1;
语句应该被修改');"
},
{
- "text": "Use the --
operator on myVar
",
- "testString": "assert(/[-]{2}\\s*myVar|myVar\\s*[-]{2}/.test(code), 'Use the --
operator on myVar
');"
+ "text": "对myVar
使用--
运算符",
+ "testString": "assert(/[-]{2}\\s*myVar|myVar\\s*[-]{2}/.test(code), '对myVar
使用--
运算符');"
},
{
- "text": "Do not change code above the line",
- "testString": "assert(/var myVar = 11;/.test(code), 'Do not change code above the line');"
+ "text": "不要修改注释上面的代码",
+ "testString": "assert(/var myVar = 11;/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -585,7 +585,7 @@
"contents": [
"var myVar = 11;",
"",
- "// Only change code below this line",
+ "// 请只修改这条注释以下的代码",
"myVar = myVar - 1;",
""
],
@@ -600,22 +600,22 @@
"id": "cf1391c1c11feddfaeb4bdef",
"title": "Create Decimal Numbers with JavaScript",
"description": [
- "We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as floating point numbers or floats.",
- "Note
Not all real numbers can accurately be represented in floating point. This can lead to rounding errors. Details Here.",
+ "我们也可以把小数存储到变量中。小数也被称作浮点数 。",
+ "提示
不是所有的实数都可以用 浮点数 来表示。因为可能存在四舍五入的错误,详情查看。",
"
",
- "Create a variable myDecimal
and give it a decimal value with a fractional part (e.g. 5.7
)."
+ "创建一个变量myDecimal
并给它赋值一个浮点数。(例如5.21
)。"
],
"solutions": [
"var myDecimal = 9.9;"
],
"tests": [
{
- "text": "myDecimal
should be a number.",
- "testString": "assert(typeof myDecimal === \"number\", 'myDecimal
should be a number.');"
+ "text": "myDecimal
应该是一个数字",
+ "testString": "assert(typeof myDecimal === \"number\", 'myDecimal
应该是一个数字');"
},
{
- "text": "myDecimal
should have a decimal point",
- "testString": "assert(myDecimal % 1 != 0, 'myDecimal
should have a decimal point'); "
+ "text": "myDecimal
应该包含小数点",
+ "testString": "assert(myDecimal % 1 != 0, 'myDecimal
应该包含小数点'); "
}
],
"challengeType": 1,
@@ -627,7 +627,7 @@
"contents": [
"var ourDecimal = 5.7;",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -642,22 +642,22 @@
"id": "bd7993c9c69feddfaeb7bdef",
"title": "Multiply Two Decimals with JavaScript",
"description": [
- "In JavaScript, you can also perform calculations with decimal numbers, just like whole numbers.",
- "Let's multiply two decimals together to get their product.",
+ "在 JavaScript 中,你也可以用小数进行计算,就像整数一样。",
+ "把两个小数相乘,并得到它们乘积。",
"
",
- "Change the 0.0
so that product will equal 5.0
."
- ],
+ "改变0.0
的数值让变量product
的值等于5.0
。"
+ ],
"solutions": [
"var product = 2.0 * 2.5;"
],
"tests": [
{
- "text": "The variable product
should equal 5.0
.",
- "testString": "assert(product === 5.0, 'The variable product
should equal 5.0
.');"
+ "text": "变量product
应该等于5.0
.",
+ "testString": "assert(product === 5.0, '变量product
应该等于5.0
.');"
},
{
- "text": "You should use the *
operator",
- "testString": "assert(/\\*/.test(code), 'You should use the *
operator');"
+ "text": "要使用*
运算符",
+ "testString": "assert(/\\*/.test(code), '要使用*
运算符');"
}
],
"challengeType": 1,
@@ -682,23 +682,23 @@
"id": "bd7993c9ca9feddfaeb7bdef",
"title": "Divide One Decimal by Another with JavaScript",
"description": [
- "Now let's divide one decimal by another.",
+ "现在让我们将一个小数除以另一个小数。",
"
",
- "Change the 0.0
so that quotient
will equal to 2.2
."
+ "改变数值0.0
的值让变量quotient
的值等于2.2
."
],
"solutions": [],
"tests": [
{
- "text": "The variable quotient
should equal 2.2
",
- "testString": "assert(quotient === 2.2, 'The variable quotient
should equal 2.2
');"
+ "text": "quotient
的值应该等于2.2
",
+ "testString": "assert(quotient === 2.2, 'quotient
的值应该等于2.2
');"
},
{
- "text": "You should use the /
operator to divide 4.4 by 2",
- "testString": "assert(/4\\.40*\\s*\\/\\s*2\\.*0*/.test(code), 'You should use the /
operator to divide 4.4 by 2');"
+ "text": "使用/
运算符将 4.4 除以 2",
+ "testString": "assert(/4\\.40*\\s*\\/\\s*2\\.*0*/.test(code), '使用/
运算符将 4.4 除以 2');"
},
{
- "text": "The quotient variable should only be assigned once",
- "testString": "assert(code.match(/quotient/g).length === 1, 'The quotient variable should only be assigned once');"
+ "text": "quotient 变量应该只被赋值一次",
+ "testString": "assert(code.match(/quotient/g).length === 1, 'quotient 变量应该只被赋值一次');"
}
],
"challengeType": 1,
@@ -708,7 +708,7 @@
"ext": "js",
"name": "index",
"contents": [
- "var quotient = 0.0 / 2.0; // Fix this line",
+ "var quotient = 0.0 / 2.0; // 修改这一行",
"",
""
],
@@ -723,14 +723,14 @@
"id": "56533eb9ac21ba0edf2244ae",
"title": "Finding a Remainder in JavaScript",
"description": [
- "The remainder operator %
gives the remainder of the division of two numbers.",
- "Example",
- "5 % 2 = 1 because
Math.floor(5 / 2) = 2 (Quotient)
2 * 2 = 4
5 - 4 = 1 (Remainder)
",
- "Usage
In mathematics, a number can be checked to be even or odd by checking the remainder of the division of the number by 2
.",
- "17 % 2 = 1 (17 is Odd)
48 % 2 = 0 (48 is Even)
",
- "Note
The remainder operator is sometimes incorrectly referred to as the \"modulus\" operator. It is very similar to modulus, but does not work properly with negative numbers.",
+ "remainder余数运算符%
对两个数取余。",
+ "示例",
+ "5 % 2 = 1 因为
Math.floor(5 / 2) = 2 (商)
2 * 2 = 4
5 - 4 = 1 (余数)
",
+ "用法
在数学中,看一个数是奇数还是偶数,只需要看这个数除以 2 得到的余数是 0 还是 1。 ",
+ "17 % 2 = 1(17 是奇数)
48 % 2 = 0(48 是偶数)
",
+ "提示
remainder余数运算符有时被错误地称为“模数”运算符。它与模数非常相似,但在负数下不能正常工作。",
"
",
- "Set remainder
equal to the remainder of 11
divided by 3
using the remainder (%
) operator."
+ "使用%
运算符,计算 11 除以 3 的余数,并把余数赋给变量remainder。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -738,16 +738,16 @@
],
"tests": [
{
- "text": "The variable remainder
should be initialized",
- "testString": "assert(/var\\s+?remainder/.test(code), 'The variable remainder
should be initialized');"
+ "text": "变量remainder
应该被初始化",
+ "testString": "assert(/var\\s+?remainder/.test(code), '变量remainder
应该被初始化');"
},
{
- "text": "The value of remainder
should be 2
",
- "testString": "assert(remainder === 2, 'The value of remainder
should be 2
');"
+ "text": "remainder
的值应该等于2
",
+ "testString": "assert(remainder === 2, 'remainder
的值应该等于2
');"
},
{
- "text": "You should use the %
operator",
- "testString": "assert(/\\s+?remainder\\s*?=\\s*?.*%.*;/.test(code), 'You should use the %
operator');"
+ "text": "你应该使用%
运算符",
+ "testString": "assert(/\\s+?remainder\\s*?=\\s*?.*%.*;/.test(code), '你应该使用%
运算符');"
}
],
"challengeType": 1,
@@ -757,7 +757,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Only change code below this line",
+ "// 请只修改这条注释以下的代码",
"",
"var remainder;",
""
@@ -773,13 +773,13 @@
"id": "56533eb9ac21ba0edf2244af",
"title": "Compound Assignment With Augmented Addition",
"description": [
- "In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say:",
+ "在编程当中,通常通过赋值来修改变量的内容。请记住,先计算=
右边,然后把计算出来的结果赋给左边。",
"myVar = myVar + 5;
",
- "to add 5
to myVar
. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.",
- "One such operator is the +=
operator.",
- "var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6
",
- "
",
- "Convert the assignments for a
, b
, and c
to use the +=
operator."
+ "以上是最常见的运算赋值语句,先运算、再赋值。还有一类操作符是一步到位既做运算也赋值的。",
+ "这类操作符的其中一种就是+=
运算符。",
+ "var myVar = 1;
myVar += 5;
console.log(myVar); // 返回 6
",
+ "
>",
+ "使用+=
操作符实现同样的效果。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -787,24 +787,24 @@
],
"tests": [
{
- "text": "a
should equal 15
",
- "testString": "assert(a === 15, 'a
should equal 15
');"
+ "text": "a
应该等于15
",
+ "testString": "assert(a === 15, 'a
应该等于15
');"
},
{
- "text": "b
should equal 26
",
- "testString": "assert(b === 26, 'b
should equal 26
');"
+ "text": "b
应该等于26
",
+ "testString": "assert(b === 26, 'b
应该等于26
');"
},
{
- "text": "c
should equal 19
",
- "testString": "assert(c === 19, 'c
should equal 19
');"
+ "text": "c
应该等于19
",
+ "testString": "assert(c === 19, 'c
应该等于19
');"
},
{
- "text": "You should use the +=
operator for each variable",
- "testString": "assert(code.match(/\\+=/g).length === 3, 'You should use the +=
operator for each variable');"
+ "text": "你应该对每个变量使用+=
操作符",
+ "testString": "assert(code.match(/\\+=/g).length === 3, '你应该对每个变量使用+=
操作符');"
},
{
- "text": "Do not modify the code above the line",
- "testString": "assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), 'Do not modify the code above the line');"
+ "text": "不要修改注释上面的代码",
+ "testString": "assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -818,7 +818,7 @@
"var b = 17;",
"var c = 12;",
"",
- "// Only modify code below this line",
+ "// 请只修改这条注释以下的代码",
"",
"a = a + 12;",
"b = 9 + b;",
@@ -836,12 +836,12 @@
"id": "56533eb9ac21ba0edf2244b0",
"title": "Compound Assignment With Augmented Subtraction",
"description": [
- "Like the +=
operator, -=
subtracts a number from a variable.",
+ "与+=
操作符类似,-=
操作符用来对一个变量进行减法赋值操作。",
"myVar = myVar - 5;
",
- "will subtract 5
from myVar
. This can be rewritten as: ",
+ "将会从变量myVar
中减去数值5
。也可以写成这种形式:",
"myVar -= 5;
",
"
",
- "Convert the assignments for a
, b
, and c
to use the -=
operator."
+ "使用-=
操作符实现同样的效果。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -849,24 +849,24 @@
],
"tests": [
{
- "text": "a
should equal 5
",
- "testString": "assert(a === 5, 'a
should equal 5
');"
+ "text": "a
应该等于5
",
+ "testString": "assert(a === 5, 'a
应该等于5
');"
},
{
- "text": "b
should equal -6
",
- "testString": "assert(b === -6, 'b
should equal -6
');"
+ "text": "b
应该等于-6
",
+ "testString": "assert(b === -6, 'b
应该等于-6
');"
},
{
- "text": "c
should equal 2
",
- "testString": "assert(c === 2, 'c
should equal 2
');"
+ "text": "c
应该等于2
",
+ "testString": "assert(c === 2, 'c
应该等于2
');"
},
{
- "text": "You should use the -=
operator for each variable",
- "testString": "assert(code.match(/-=/g).length === 3, 'You should use the -=
operator for each variable');"
+ "text": "应该对每个变量使用-=
操作符",
+ "testString": "assert(code.match(/-=/g).length === 3, '应该对每个变量使用-=
操作符');"
},
{
- "text": "Do not modify the code above the line",
- "testString": "assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), 'Do not modify the code above the line');"
+ "text": "不要修改注释上面的代码",
+ "testString": "assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -880,7 +880,7 @@
"var b = 9;",
"var c = 3;",
"",
- "// Only modify code below this line",
+ "// 请只修改这条注释以下的代码",
"",
"a = a - 6;",
"b = b - 15;",
@@ -899,12 +899,12 @@
"id": "56533eb9ac21ba0edf2244b1",
"title": "Compound Assignment With Augmented Multiplication",
"description": [
- "The *=
operator multiplies a variable by a number.",
+ "*=
操作符是让变量与一个数相乘并赋值。",
"myVar = myVar * 5;
",
- "will multiply myVar
by 5
. This can be rewritten as: ",
+ "将会把变量myVar
与数值5
相乘。也可以写作这样的形式: ",
"myVar *= 5;
",
"
",
- "Convert the assignments for a
, b
, and c
to use the *=
operator."
+ "使用*=
操作符实现同样的效果。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -912,24 +912,24 @@
],
"tests": [
{
- "text": "a
should equal 25
",
- "testString": "assert(a === 25, 'a
should equal 25
');"
+ "text": "a
应该等于25
",
+ "testString": "assert(a === 25, 'a
应该等于25
');"
},
{
- "text": "b
should equal 36
",
- "testString": "assert(b === 36, 'b
should equal 36
');"
+ "text": "b
应该等于36
",
+ "testString": "assert(b === 36, 'b
应该等于36
');"
},
{
- "text": "c
should equal 46
",
- "testString": "assert(c === 46, 'c
should equal 46
');"
+ "text": "c
应该等于46
",
+ "testString": "assert(c === 46, 'c
应该等于46
');"
},
{
- "text": "You should use the *=
operator for each variable",
- "testString": "assert(code.match(/\\*=/g).length === 3, 'You should use the *=
operator for each variable');"
+ "text": "应该对每个变量使用*=
操作符",
+ "testString": "assert(code.match(/\\*=/g).length === 3, '应该对每个变量使用*=
操作符');"
},
{
- "text": "Do not modify the code above the line",
- "testString": "assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\\.6;/.test(code), 'Do not modify the code above the line');"
+ "text": "不要修改注释上面的代码",
+ "testString": "assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\\.6;/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -943,7 +943,7 @@
"var b = 12;",
"var c = 4.6;",
"",
- "// Only modify code below this line",
+ "// 请只修改这条注释以下的代码",
"",
"a = a * 5;",
"b = 3 * b;",
@@ -962,12 +962,12 @@
"id": "56533eb9ac21ba0edf2244b2",
"title": "Compound Assignment With Augmented Division",
"description": [
- "The /=
operator divides a variable by another number.",
+ "/=
操作符是让变量与另一个数相除并赋值。",
"myVar = myVar / 5;
",
- "Will divide myVar
by 5
. This can be rewritten as: ",
+ "会把变量myVar
的值除于5
。等价于: ",
"myVar /= 5;
",
"
",
- "Convert the assignments for a
, b
, and c
to use the /=
operator."
+ "使用/=
操作符实现同样的效果。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -975,24 +975,24 @@
],
"tests": [
{
- "text": "a
should equal 4
",
- "testString": "assert(a === 4, 'a
should equal 4
');"
+ "text": "a
应该等于4
",
+ "testString": "assert(a === 4, 'a
应该等于4
');"
},
{
- "text": "b
should equal 27
",
- "testString": "assert(b === 27, 'b
should equal 27
');"
+ "text": "b
应该等于27
",
+ "testString": "assert(b === 27, 'b
应该等于27
');"
},
{
- "text": "c
should equal 3
",
- "testString": "assert(c === 3, 'c
should equal 3
');"
+ "text": "c
应该等于3
",
+ "testString": "assert(c === 3, 'c
应该等于3
');"
},
{
- "text": "You should use the /=
operator for each variable",
- "testString": "assert(code.match(/\\/=/g).length === 3, 'You should use the /=
operator for each variable');"
+ "text": "应该对每个变量使用/=
操作符",
+ "testString": "assert(code.match(/\\/=/g).length === 3, '应该对每个变量使用/=
操作符');"
},
{
- "text": "Do not modify the code above the line",
- "testString": "assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), 'Do not modify the code above the line');"
+ "text": "不要修改注释上面的代码",
+ "testString": "assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -1006,7 +1006,7 @@
"var b = 108;",
"var c = 33;",
"",
- "// Only modify code below this line",
+ "// 请只修改这条注释以下的代码",
"",
"a = a / 12;",
"b = b / 4;",
@@ -1024,23 +1024,23 @@
"id": "bd7123c9c444eddfaeb5bdef",
"title": "Declare String Variables",
"description": [
- "Previously we have used the code",
+ "先前我们使用过的代码:",
"var myName = \"your name\";
",
- "\"your name\"
is called a string literal. It is a string because it is a series of zero or more characters enclosed in single or double quotes.",
+ "\"your name\"
被称作字符串。字符串是用单引号或双引号包裹起来的一连串的零个或多个字符。",
"
",
- "Create two new string
variables: myFirstName
and myLastName
and assign them the values of your first and last name, respectively."
+ "创建两个新的字符串
变量:myFirstName
和myLastName
分别为它们赋上你的姓和名的值。"
],
"solutions": [
"var myFirstName = \"Alan\";\nvar myLastName = \"Turing\";"
],
"tests": [
{
- "text": "myFirstName
should be a string with at least one character in it.",
- "testString": "assert((function(){if(typeof myFirstName !== \"undefined\" && typeof myFirstName === \"string\" && myFirstName.length > 0){return true;}else{return false;}})(), 'myFirstName
should be a string with at least one character in it.');"
+ "text": "myFirstName
应该是一个字符串,并且至少包含一个字符。",
+ "testString": "assert((function(){if(typeof myFirstName !== \"undefined\" && typeof myFirstName === \"string\" && myFirstName.length > 0){return true;}else{return false;}})(), 'myFirstName
应该是一个字符串,并且至少包含一个字符。');"
},
{
- "text": "myLastName
should be a string with at least one character in it.",
- "testString": "assert((function(){if(typeof myLastName !== \"undefined\" && typeof myLastName === \"string\" && myLastName.length > 0){return true;}else{return false;}})(), 'myLastName
should be a string with at least one character in it.');"
+ "text": "myLastName
应该是一个字符串,并且至少包含一个字符。",
+ "testString": "assert((function(){if(typeof myLastName !== \"undefined\" && typeof myLastName === \"string\" && myLastName.length > 0){return true;}else{return false;}})(), 'myLastName
应该是一个字符串,并且至少包含一个字符。');"
}
],
"challengeType": 1,
@@ -1050,11 +1050,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstName = \"Alan\";",
"var lastName = \"Turing\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -1069,14 +1069,14 @@
"id": "56533eb9ac21ba0edf2244b5",
"title": "Escaping Literal Quotes in Strings",
"description": [
- "When you are defining a string you must start and end with a single or double quote. What happens when you need a literal quote: \"
or '
inside of your string?",
- "In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash (\\
) in front of the quote.",
+ "当你定义一个字符串必须要用单引号或双引号来包裹它。那么当你需要在字符串中使用一个:\"
或者'
时该怎么办呢?",
+ "在 JavaScript 中,你可以通过在引号前面使用 反斜杠 (\\
) 来转义引号。",
"var sampleStr = \"Alan said, \\\"Peter is learning JavaScript\\\".\";
",
- "This signals to JavaScript that the following quote is not the end of the string, but should instead appear inside the string. So if you were to print this to the console, you would get:",
+ "这标志着提醒 JavaScript 单引号或双引号并不是字符串的结尾,而是出现在字符串内的字符。所以,如果你要打印字符串到控制台,你将得到:",
"Alan said, \"Peter is learning JavaScript\".
",
"
",
- "Use backslashes to assign a string to the myStr
variable so that if you were to print it to the console, you would see:",
- "I am a \"double quoted\" string inside \"double quotes\".
"
+ "使用 反斜杠 将一个字符串赋值给变量myStr
,以便如果你要打印到控制台,你会看到:",
+ "I am a \"double quoted\" string inside \"double quotes\"
"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1084,12 +1084,12 @@
],
"tests": [
{
- "text": "You should use two double quotes ("
) and four escaped double quotes (\"
).",
- "testString": "assert(code.match(/\\\\\"/g).length === 4 && code.match(/[^\\\\]\"/g).length === 2, 'You should use two double quotes ("
) and four escaped double quotes (\"
).');"
+ "text": "你的代码中应该包含两个双引号 ("
) 以及四个转义的双引 (\"
).",
+ "testString": "assert(code.match(/\\\\\"/g).length === 4 && code.match(/[^\\\\]\"/g).length === 2, '你的代码中应该包含两个双引号 ("
) 以及四个转义的双引 (\"
).');"
},
{
- "text": "Variable myStr should contain the string: I am a \"double quoted\" string inside \"double quotes\".
",
- "testString": "assert(myStr === \"I am a \\\"double quoted\\\" string inside \\\"double quotes\\\".\", 'Variable myStr should contain the string: I am a \"double quoted\" string inside \"double quotes\".
');"
+ "text": "变量 myStr 应该包含字符串I am a \"double quoted\" string inside \"double quotes\".
",
+ "testString": "assert(myStr === \"I am a \\\"double quoted\\\" string inside \\\"double quotes\\\".\", '变量 myStr 应该包含字符串I am a \"double quoted\" string inside \"double quotes\".
');"
}
],
"challengeType": 1,
@@ -1099,7 +1099,7 @@
"ext": "js",
"name": "index",
"contents": [
- "var myStr = \"\"; // Change this line",
+ "var myStr = \"\"; // 请修改这一行",
"",
""
],
@@ -1120,17 +1120,17 @@
"id": "56533eb9ac21ba0edf2244b4",
"title": "Quoting Strings with Single Quotes",
"description": [
- "String values in JavaScript may be written with single or double quotes, as long as you start and end with the same type of quote. Unlike some other programming languages, single and double quotes work the same in JavaScript.",
+ "在 JavaScript 中的 字符串 要用单引号或双引号来包裹它,只要你在开始和结束都使用相同类型的引号,单引号和双引号的功能在JavaScript中是相同的。",
"doubleQuoteStr = \"This is a string\";
singleQuoteStr = 'This is also a string';
",
- "The reason why you might want to use one type of quote over the other is if you want to use both in a string. This might happen if you want to save a conversation in a string and have the conversation in quotes. Another use for it would be saving an <a>
tag with various attributes in quotes, all within a string.",
+ "当你需要在一个字符串中使用多个引号的时候,你可以使用一种类型的引号包裹另一种类型的引号。常见的场景比如在字符串中保存的句子包含对话,需要用引号包裹的时候。另外一个用处是在一个字符串中保存带有用引号包裹的属性的<a>
标签的时候。",
"conversation = 'Finn exclaims to Jake, \"Algebraic!\"';
",
- "However, this becomes a problem if you need to use the outermost quotes within it. Remember, a string has the same kind of quote at the beginning and end. But if you have that same quote somewhere in the middle, the string will stop early and throw an error.",
- "goodStr = 'Jake asks Finn, \"Hey, let\\'s go on an adventure?\"';
badStr = 'Finn responds, \"Let's go!\"'; // Throws an error
",
- "In the goodStr above, you can use both quotes safely by using the backslash \\
as an escape character.",
- "Note
The backslash \\
should not be be confused with the forward slash /
. They do not do the same thing.",
+ "但是,如果你想值字符串中使用与最外层相同的引号,会有一些问题。要记住,字符串在开头和结尾都有相同的引号,如果在中间使用了相同的引号,字符串将提前中止并抛出错误。",
+ "goodStr = 'Jake asks Finn, \"Hey, let\\'s go on an adventure?\"';
badStr = 'Finn responds, \"Let's go!\"'; // 抛出错误
",
+ "在上面的goodStr中,可以使用反斜杠\\
转义字符安全地使用两个引号",
+ "提示
不要把反斜杠\\
和斜杠/
搞混,它们不是一回事。",
"
",
- "Change the provided string to a string with single quotes at the beginning and end and no escape characters.",
- "Right now, the <a>
tag in the string uses double quotes everywhere. You will need to change the outer quotes to single quotes so you can remove the escape characters."
+ "将字符串更改为在开头和结尾使用单引号的字符串,并且不包含转义字符。",
+ "然后字符串中的<a>
标签在任何地方都可以使用双引号。你需要将最外层引号更改为单引号,以便删除转义字符。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1138,12 +1138,12 @@
],
"tests": [
{
- "text": "Remove all the backslashes
(\\
)",
- "testString": "assert(!/\\\\/g.test(code) && myStr.match('\\\\s*\\\\s*Link\\\\s*\\\\s*'), 'Remove all the backslashes
(\\
)');"
+ "text": "删除所有反斜杠
(\\
)",
+ "testString": "assert(!/\\\\/g.test(code) && myStr.match('\\\\s*\\\\s*Link\\\\s*\\\\s*'), '删除所有反斜杠
(\\
)');"
},
{
- "text": "You should have two single quotes '
and four double quotes "
",
- "testString": "assert(code.match(/\"/g).length === 4 && code.match(/'/g).length === 2, 'You should have two single quotes '
and four double quotes "
');"
+ "text": "应该要有两个单引号'
和四个双引号"
",
+ "testString": "assert(code.match(/\"/g).length === 4 && code.match(/'/g).length === 2, '应该要有两个单引号'
和四个双引号"
');"
}
],
"challengeType": 1,
@@ -1168,15 +1168,15 @@
"id": "56533eb9ac21ba0edf2244b6",
"title": "Escape Sequences in Strings",
"description": [
- "Quotes are not the only characters that can be escaped inside a string. There are two reasons to use escaping characters: First is to allow you to use characters you might not otherwise be able to type out, such as a backspace. Second is to allow you to represent multiple quotes in a string without JavaScript misinterpreting what you mean. We learned this in the previous challenge.",
- "Code | Output |
---|
\\' | single quote |
\\\" | double quote |
\\\\ | backslash |
\\n | newline |
\\r | carriage return |
\\t | tab |
\\b | backspace |
\\f | form feed |
",
- "Note that the backslash itself must be escaped in order to display as a backslash.",
+ "引号不是字符串中唯一的可以被转义escaped的字符。使用转义字符有两个原因:首先是可以让你使用无法输入的字符,例如退格。其次是可以让你在一个字符串中表示多个引号,而不会出错。我们在之前的挑战中学到了这一点。",
+ "代码 | 输出 |
---|
\\' | 单引号 |
\\\" | 双引号 |
\\\\ | 反斜杠 |
\\n | 换行符 |
\\r | 回车符 |
\\t | 制表符 |
\\b | backspace |
\\f | 换页符 |
",
+ "请注意,必须对反斜杠本身进行转义才能显示为反斜杠。",
"
",
- "Assign the following three lines of text into the single variable myStr
using escape sequences.",
+ "使用转义字符将下面三行文本字符串赋给变量myStr
。",
"FirstLine
\\SecondLine
ThirdLine
",
- "You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.",
- "Here is the text with the escape sequences written out.",
- "FirstLinenewline
tab
backslash
SecondLinenewline
ThirdLine
"
+ "你需要使用转义字符正确的插入特殊字符,确保间距与上面文本一致并且单词或转义字符之间没有空格。",
+ "像这样用转义字符写出来:",
+ "FirstLine换行符
制表符
反斜杠
SecondLine换行符
ThirdLine
"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1184,28 +1184,28 @@
],
"tests": [
{
- "text": "myStr
should not contain any spaces",
+ "text": "myStr
不能包含空格",
"testString": "assert(!/ /.test(myStr), 'myStr
should not contain any spaces');"
},
{
- "text": "myStr
should contain the strings FirstLine
, SecondLine
and ThirdLine
(remember case sensitivity)",
- "testString": "assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr), 'myStr
should contain the strings FirstLine
, SecondLine
and ThirdLine
(remember case sensitivity)');"
+ "text": "myStr
应该包含字符串FirstLine
, SecondLine
and ThirdLine
(记得区分大小写)",
+ "testString": "assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr), 'myStr
应该包含字符串FirstLine
, SecondLine
and ThirdLine
(记得区分大小写)');"
},
{
- "text": "FirstLine
should be followed by the newline character \\n
",
- "testString": "assert(/FirstLine\\n/.test(myStr), 'FirstLine
should be followed by the newline character \\n
');"
+ "text": "FirstLine
后面应该是一个新行\\n
",
+ "testString": "assert(/FirstLine\\n/.test(myStr), 'FirstLine
后面应该是一个换行符\\n
');"
},
{
- "text": "myStr
should contain a tab character \\t
which follows a newline character",
- "testString": "assert(/\\n\\t/.test(myStr), 'myStr
should contain a tab character \\t
which follows a newline character');"
+ "text": "myStr
应该包含制表符\\t
并且制表符要在换行符后面",
+ "testString": "assert(/\\n\\t/.test(myStr), 'myStr
应该包含制表符\\t
并且制表符要在换行符后面');"
},
{
- "text": "SecondLine
should be preceded by the backslash character \\\\
",
- "testString": "assert(/\\SecondLine/.test(myStr), 'SecondLine
should be preceded by the backslash character \\\\
');"
+ "text": "SecondLine
前面应该是反斜杠\\\\
",
+ "testString": "assert(/\\SecondLine/.test(myStr), 'SecondLine
前面应该是反斜杠\\\\
');"
},
{
- "text": "There should be a newline character between SecondLine
and ThirdLine
",
- "testString": "assert(/SecondLine\\nThirdLine/.test(myStr), 'There should be a newline character between SecondLine
and ThirdLine
');"
+ "text": "SecondLine
和ThirdLine
之间应该是换行符",
+ "testString": "assert(/SecondLine\\nThirdLine/.test(myStr), 'SecondLine
和ThirdLine
之间该是换行符');"
}
],
"challengeType": 1,
@@ -1215,7 +1215,7 @@
"ext": "js",
"name": "index",
"contents": [
- "var myStr; // Change this line",
+ "var myStr; // 请修改这一行",
"",
""
],
@@ -1232,12 +1232,12 @@
"id": "56533eb9ac21ba0edf2244b7",
"title": "Concatenating Strings with Plus Operator",
"description": [
- "In JavaScript, when the +
operator is used with a String
value, it is called the concatenation operator. You can build a new string out of other strings by concatenating them together.",
- "Example",
+ "在 JavaScript 中,当对一个String
类型的值使用+
操作符的时候,它被称作 concatenation 操作符。你可以通过和其他字符串concatenation来创建一个新的字符串。",
+ "示例",
"'My name is Alan,' + ' I concatenate.'
",
- "Note
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.",
+ "提示
注意空格。拼接操作不会在两个字符串之间添加空格,所以想加上空格的话,你需要自己在字符串里面添加。",
"
",
- "Build myStr
from the strings \"This is the start. \"
and \"This is the end.\"
using the +
operator."
+ "使用+
操作符,把字符串\"This is the start. \"
和\"This is the end.\"
连接起来并赋值给变量myStr
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1245,20 +1245,20 @@
],
"tests": [
{
- "text": "myStr
should have a value of This is the start. This is the end.
",
- "testString": "assert(myStr === \"This is the start. This is the end.\", 'myStr
should have a value of This is the start. This is the end.
');"
+ "text": "myStr
的值应该是This is the start. This is the end.
",
+ "testString": "assert(myStr === \"This is the start. This is the end.\", 'myStr
的值应该是This is the start. This is the end.
');"
},
{
- "text": "Use the +
operator to build myStr
",
- "testString": "assert(code.match(/([\"']).*([\"'])\\s*\\+\\s*([\"']).*([\"'])/g).length > 1, 'Use the +
operator to build myStr
');"
+ "text": "使用+
操作符构建myStr
",
+ "testString": "assert(code.match(/([\"']).*([\"'])\\s*\\+\\s*([\"']).*([\"'])/g).length > 1, '使用+
操作符构建myStr
');"
},
{
- "text": "myStr
should be created using the var
keyword.",
- "testString": "assert(/var\\s+myStr/.test(code), 'myStr
should be created using the var
keyword.');"
+ "text": "myStr
应该被var
关键字声明",
+ "testString": "assert(/var\\s+myStr/.test(code), 'myStr
应该被var
关键字声明');"
},
{
- "text": "Make sure to assign the result to the myStr
variable.",
- "testString": "assert(/myStr\\s*=/.test(code), 'Make sure to assign the result to the myStr
variable.');"
+ "text": "确保有给myStr
赋值",
+ "testString": "assert(/myStr\\s*=/.test(code), '确保有给myStr
赋值');"
}
],
"challengeType": 1,
@@ -1268,10 +1268,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourStr = \"I come first. \" + \"I come second.\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"var myStr;",
"",
@@ -1294,10 +1294,10 @@
"id": "56533eb9ac21ba0edf2244b8",
"title": "Concatenating Strings with the Plus Equals Operator",
"description": [
- "We can also use the +=
operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.",
- "Note
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.",
+ "我们还可以使用+=
运算符来concatenate(拼接)字符串到现有字符串的结尾。对于那些被分割成几段的长的字符串来说,这一操作是非常有用的。",
+ "提示
注意空格。连接操作不会添加两个字符串外面的空格,所以如果想要加上空格的话,你需要自己在字符串里面添加。",
"
",
- "Build myStr
over several lines by concatenating these two strings: \"This is the first sentence. \"
and \"This is the second sentence.\"
using the +=
operator. Use the +=
operator similar to how it is shown in the editor. Start by assigning the first string to myStr
, then add on the second string."
+ "通过使用+=
操作符来连接这两个字符串:
\"This is the first sentence. \"
和\"This is the second sentence.\"
并赋给变量myStr
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1305,12 +1305,12 @@
],
"tests": [
{
- "text": "myStr
should have a value of This is the first sentence. This is the second sentence.
",
- "testString": "assert(myStr === \"This is the first sentence. This is the second sentence.\", 'myStr
should have a value of This is the first sentence. This is the second sentence.
');"
+ "text": "myStr
的值应该是This is the first sentence. This is the second sentence.
",
+ "testString": "assert(myStr === \"This is the first sentence. This is the second sentence.\", 'myStr
的值应该是This is the first sentence. This is the second sentence.
');"
},
{
- "text": "Use the +=
operator to build myStr
",
- "testString": "assert(code.match(/\\w\\s*\\+=\\s*[\"']/g).length > 1 && code.match(/\\w\\s*\\=\\s*[\"']/g).length > 1, 'Use the +=
operator to build myStr
');"
+ "text": "使用+=
操作符创建myStr
变量",
+ "testString": "assert(code.match(/\\w\\s*\\+=\\s*[\"']/g).length > 1 && code.match(/\\w\\s*\\=\\s*[\"']/g).length > 1, '使用+=
操作符创建myStr
变量');"
}
],
"challengeType": 1,
@@ -1320,11 +1320,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourStr = \"I come first. \";",
"ourStr += \"I come second.\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"var myStr;",
"",
@@ -1347,9 +1347,9 @@
"id": "56533eb9ac21ba0edf2244b9",
"title": "Constructing Strings with Variables",
"description": [
- "Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (+
), you can insert one or more variables into a string you're building.",
+ "有时候你需要创建一个类似Mad Libs(填词游戏)风格的字符串。通过使用连接运算符 +
,你可以插入一个或多个变量来组成一个字符串。",
"
",
- "Set myName
to a string equal to your name and build myStr
with myName
between the strings \"My name is \"
and \" and I am well!\"
"
+ "把你的名字赋值给变量myName
,然后把变量myName
插入到字符串\"My name is \"
和\" and I am well!\"
之间,并把连接后的结果赋值给变量myStr
。 "
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1357,12 +1357,12 @@
],
"tests": [
{
- "text": "myName
should be set to a string at least 3 characters long",
- "testString": "assert(typeof myName !== 'undefined' && myName.length > 2, 'myName
should be set to a string at least 3 characters long');"
+ "text": "myName
至少要包含三个字符",
+ "testString": "assert(typeof myName !== 'undefined' && myName.length > 2, 'myName
至少要包含三个字符');"
},
{
- "text": "Use two +
operators to build myStr
with myName
inside it",
- "testString": "assert(code.match(/[\"']\\s*\\+\\s*myName\\s*\\+\\s*[\"']/g).length > 0, 'Use two +
operators to build myStr
with myName
inside it');"
+ "text": "使用两个+
操作符创建包含myName
的myStr
变量",
+ "testString": "assert(code.match(/[\"']\\s*\\+\\s*myName\\s*\\+\\s*[\"']/g).length > 0, '使用两个+
操作符创建包含myName
的myStr
变量');"
}
],
"challengeType": 1,
@@ -1372,11 +1372,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourName = \"freeCodeCamp\";",
"var ourStr = \"Hello, our name is \" + ourName + \", how are you?\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"var myName;",
"var myStr;",
"",
@@ -1406,9 +1406,9 @@
"id": "56533eb9ac21ba0edf2244ed",
"title": "Appending Variables to Strings",
"description": [
- "Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=
) operator.",
+ "我们不仅可以创建出多行的字符串,还可以使用加等号(+=
)运算符来追加变量到字符串上。",
"
",
- "Set someAdjective
and append it to myStr
using the +=
operator."
+ "设置变量someAdjective
的值,并使用+=
运算符把它追加到变量myStr
上。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1416,12 +1416,12 @@
],
"tests": [
{
- "text": "someAdjective
should be set to a string at least 3 characters long",
- "testString": "assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2, 'someAdjective
should be set to a string at least 3 characters long');"
+ "text": "someAdjective
应该是一个至少包含三个字符的字符串",
+ "testString": "assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2, 'someAdjective
应该是一个至少包含三个字符的字符串');"
},
{
- "text": "Append someAdjective
to myStr
using the +=
operator",
- "testString": "assert(code.match(/myStr\\s*\\+=\\s*someAdjective\\s*/).length > 0, 'Append someAdjective
to myStr
using the +=
operator');"
+ "text": "使用+=
操作符把someAdjective
追加到myStr
的后面",
+ "testString": "assert(code.match(/myStr\\s*\\+=\\s*someAdjective\\s*/).length > 0, '使用+=
操作符把someAdjective
追加到myStr
的后面');"
}
],
"challengeType": 1,
@@ -1432,12 +1432,12 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var anAdjective = \"awesome!\";",
"var ourStr = \"freeCodeCamp is \";",
"ourStr += anAdjective;",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"var someAdjective;",
"var myStr = \"Learning to code is \";",
@@ -1467,23 +1467,23 @@
"id": "bd7123c9c448eddfaeb5bdef",
"title": "Find the Length of a String",
"description": [
- "You can find the length of a String
value by writing .length
after the string variable or string literal.",
+ "你可以通过在字符串变量或字符串后面写上.length
来获得字符串变量字符串
值的长度。",
"\"Alan Peter\".length; // 10
",
- "For example, if we created a variable var firstName = \"Charles\"
, we could find out how long the string \"Charles\"
is by using the firstName.length
property.",
+ "例如,我们创建了一个变量var firstName = \"Charles\"
,我们就可以通过使用firstName.length
来获得\"Charles\"
字符串的长度。",
"
",
- "Use the .length
property to count the number of characters in the lastName
variable and assign it to lastNameLength
."
+ "使用.length
属性来获得变量lastName
的长度,并把它赋值给变量lastNameLength
。"
],
"solutions": [
"var firstNameLength = 0;\nvar firstName = \"Ada\";\nfirstNameLength = firstName.length;\n\nvar lastNameLength = 0;\nvar lastName = \"Lovelace\";\nlastNameLength = lastName.length;"
],
"tests": [
{
- "text": "lastNameLength
should be equal to eight.",
- "testString": "assert((function(){if(typeof lastNameLength !== \"undefined\" && typeof lastNameLength === \"number\" && lastNameLength === 8){return true;}else{return false;}})(), 'lastNameLength
should be equal to eight.');"
+ "text": "lastNameLength
应该等于 8",
+ "testString": "assert((function(){if(typeof lastNameLength !== \"undefined\" && typeof lastNameLength === \"number\" && lastNameLength === 8){return true;}else{return false;}})(), 'lastNameLength
应该等于 8');"
},
{
- "text": "You should be getting the length of lastName
by using .length
like this: lastName.length
.",
- "testString": "assert((function(){if(code.match(/\\.length/gi) && code.match(/\\.length/gi).length >= 2 && code.match(/var lastNameLength \\= 0;/gi) && code.match(/var lastNameLength \\= 0;/gi).length >= 1){return true;}else{return false;}})(), 'You should be getting the length of lastName
by using .length
like this: lastName.length
.');"
+ "text": "你应该使用.length
获取lastName
的长度, 像这样:lastName.length
",
+ "testString": "assert((function(){if(code.match(/\\.length/gi) && code.match(/\\.length/gi).length >= 2 && code.match(/var lastNameLength \\= 0;/gi) && code.match(/var lastNameLength \\= 0;/gi).length >= 1){return true;}else{return false;}})(), '你应该使用.length
获取lastName
的长度, 像这样:lastName.length
');"
}
],
"challengeType": 1,
@@ -1493,17 +1493,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstNameLength = 0;",
"var firstName = \"Ada\";",
"",
"firstNameLength = firstName.length;",
"",
- "// Setup",
+ "// 初始化",
"var lastNameLength = 0;",
"var lastName = \"Lovelace\";",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
"lastNameLength = lastName;",
"",
@@ -1520,24 +1520,24 @@
"id": "bd7123c9c549eddfaeb5bdef",
"title": "Use Bracket Notation to Find the First Character in a String",
"description": [
- "Bracket notation
is a way to get a character at a specific index
within a string.",
- "Most modern programming languages, like JavaScript, don't start counting at 1 like humans do. They start at 0. This is referred to as Zero-based indexing.",
- "For example, the character at index 0 in the word \"Charles\" is \"C\". So if var firstName = \"Charles\"
, you can get the value of the first letter of the string by using firstName[0]
.",
+ "方括号表示法是一种在字符串中的特定index
(索引)处获取字符的方法。",
+ "大多数现代编程语言,如JavaScript,不同于人类从 1 开始计数。它们是从 0 开始计数,这被称为 基于零 的索引。",
+ "例如, 在单词 \"Charles\" 中索引 0 上的字符为 \"C\",所以在var firstName = \"Charles\"
中,你可以使用firstName[0]
来获得第一个位置上的字符。",
"
",
- "Use bracket notation to find the first character in the lastName
variable and assign it to firstLetterOfLastName
.",
- "Hint
Try looking at the firstLetterOfFirstName
variable declaration if you get stuck."
+ "使用方括号获取变量lastName
中的第一个字符,并赋给变量firstLetterOfLastName
。",
+ "提示
如果你遇到困难了,不妨看看变量firstLetterOfFirstName
是如何赋值的。"
],
"solutions": [
- "var firstLetterOfLastName = \"\";\nvar lastName = \"Lovelace\";\n\n// Only change code below this line\nfirstLetterOfLastName = lastName[0];"
+ "var firstLetterOfLastName = \"\";\nvar lastName = \"Lovelace\";\n\n// 请把你的代码写在这条注释以下\nfirstLetterOfLastName = lastName[0];"
],
"tests": [
{
- "text": "The firstLetterOfLastName
variable should have the value of L
.",
- "testString": "assert(firstLetterOfLastName === 'L', 'The firstLetterOfLastName
variable should have the value of L
.');"
+ "text": "firstLetterOfLastName
的值应该是L
",
+ "testString": "assert(firstLetterOfLastName === 'L', 'firstLetterOfLastName
的值应该是L
');"
},
{
- "text": "You should use bracket notation.",
- "testString": "assert(code.match(/firstLetterOfLastName\\s*?=\\s*?lastName\\[.*?\\]/), 'You should use bracket notation.');"
+ "text": "你应该使用中括号",
+ "testString": "assert(code.match(/firstLetterOfLastName\\s*?=\\s*?lastName\\[.*?\\]/), '你应该使用中括号');"
}
],
"challengeType": 1,
@@ -1547,17 +1547,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstLetterOfFirstName = \"\";",
"var firstName = \"Ada\";",
"",
"firstLetterOfFirstName = firstName[0];",
"",
- "// Setup",
+ "// 初始化",
"var firstLetterOfLastName = \"\";",
"var lastName = \"Lovelace\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"firstLetterOfLastName = lastName;",
"",
""
@@ -1573,13 +1573,13 @@
"id": "56533eb9ac21ba0edf2244ba",
"title": "Understand String Immutability",
"description": [
- "In JavaScript, String
values are immutable, which means that they cannot be altered once created.",
- "For example, the following code:",
+ "在 JavaScript 中,字符串
的值是 不可变的,这意味着一旦字符串被创建就不能被改变。",
+ "例如,下面的代码:",
"var myStr = \"Bob\";
myStr[0] = \"J\";
",
- "cannot change the value of myStr
to \"Job\", because the contents of myStr
cannot be altered. Note that this does not mean that myStr
cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change myStr
would be to assign it with a new string, like this:",
+ "是不会把变量myStr
的值改变成 \"Job\" 的,因为变量myStr
是不可变的。注意,这并不意味着myStr
永远不能被改变,只是字符串字面量 string literal 的各个字符不能被改变。改变myStr
中的唯一方法是重新给它赋一个值,例如:",
"var myStr = \"Bob\";
myStr = \"Job\";
",
"
",
- "Correct the assignment to myStr
so it contains the string value of Hello World
using the approach shown in the example above."
+ "把myStr
的值改为Hello World
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1587,12 +1587,12 @@
],
"tests": [
{
- "text": "myStr
should have a value of Hello World
",
- "testString": "assert(myStr === \"Hello World\", 'myStr
should have a value of Hello World
');"
+ "text": "message:myStr
的值应该是Hello World
",
+ "testString": "assert(myStr === \"Hello World\", 'message:myStr
的值应该是Hello World
');"
},
{
"text": "Do not change the code above the line",
- "testString": "assert(/myStr = \"Jello World\"/.test(code), 'Do not change the code above the line');"
+ "testString": "assert(/myStr = \"Jello World\"/.test(code), '不要修改注释上面的代码');"
}
],
"challengeType": 1,
@@ -1602,10 +1602,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myStr = \"Jello World\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"myStr[0] = \"H\"; // Fix Me",
"",
@@ -1622,23 +1622,23 @@
"id": "bd7123c9c450eddfaeb5bdef",
"title": "Use Bracket Notation to Find the Nth Character in a String",
"description": [
- "You can also use bracket notation to get the character at other positions within a string.",
- "Remember that computers start counting at 0
, so the first character is actually the zeroth character.",
+ "你也可以使用方括号来获得一个字符串中的其他位置的字符。",
+ "请记住,程序是从0
开始计数,所以获取第一个字符实际上是[0]。",
"
",
- "Let's try to set thirdLetterOfLastName
to equal the third letter of the lastName
variable using bracket notation.",
- "Hint
Try looking at the secondLetterOfFirstName
variable declaration if you get stuck."
+ "让我们使用方括号,把lastName
变量的第三个字符赋值给thirdLetterOfLastName
。",
+ "提示
如果你遇到困难了,看看secondLetterOfFirstName
变量是如何做的。"
],
"solutions": [
"var lastName = \"Lovelace\";\nvar thirdLetterOfLastName = lastName[2];"
],
"tests": [
{
- "text": "The thirdLetterOfLastName
variable should have the value of v
.",
- "testString": "assert(thirdLetterOfLastName === 'v', 'The thirdLetterOfLastName
variable should have the value of v
.');"
+ "text": "thirdLetterOfLastName
的值应该是v
",
+ "testString": "assert(thirdLetterOfLastName === 'v', 'thirdLetterOfLastName
的值应该是v
');"
},
{
- "text": "You should use bracket notation.",
- "testString": "assert(code.match(/thirdLetterOfLastName\\s*?=\\s*?lastName\\[.*?\\]/), 'You should use bracket notation.');"
+ "text": "你应该使用方括号",
+ "testString": "assert(code.match(/thirdLetterOfLastName\\s*?=\\s*?lastName\\[.*?\\]/), '你应该使用方括号');"
}
],
"challengeType": 1,
@@ -1648,14 +1648,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstName = \"Ada\";",
"var secondLetterOfFirstName = firstName[1];",
"",
- "// Setup",
+ "// 初始化变量",
"var lastName = \"Lovelace\";",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var thirdLetterOfLastName = lastName;",
"",
""
@@ -1671,23 +1671,23 @@
"id": "bd7123c9c451eddfaeb5bdef",
"title": "Use Bracket Notation to Find the Last Character in a String",
"description": [
- "In order to get the last letter of a string, you can subtract one from the string's length.",
- "For example, if var firstName = \"Charles\"
, you can get the value of the last letter of the string by using firstName[firstName.length - 1]
.",
+ "要获取字符串的最后一个字符,可以用字符串的长度减 1 的索引值。",
+ "例如,在var firstName = \"Charles\"
中,你可以这样操作firstName[firstName.length - 1]
来得到字符串的最后的一个字符。",
"
",
- "Use bracket notation to find the last character in the lastName
variable.",
- "Hint
Try looking at the lastLetterOfFirstName
variable declaration if you get stuck."
+ "使用方括号lastName变量中的最后一个字符。",
+ "提示
如果你遇到困难了,不妨看看在lastLetterOfFirstName
变量上是怎么做的。"
],
"solutions": [
"var firstName = \"Ada\";\nvar lastLetterOfFirstName = firstName[firstName.length - 1];\n\nvar lastName = \"Lovelace\";\nvar lastLetterOfLastName = lastName[lastName.length - 1];"
],
"tests": [
{
- "text": "lastLetterOfLastName
should be \"e\".",
- "testString": "assert(lastLetterOfLastName === \"e\", 'lastLetterOfLastName
should be \"e\".');"
+ "text": "lastLetterOfLastName
应该是\"e\".",
+ "testString": "assert(lastLetterOfLastName === \"e\", 'lastLetterOfLastName
应该是 \"e\".');"
},
{
- "text": "You have to use .length
to get the last letter.",
- "testString": "assert(code.match(/\\.length/g).length === 2, 'You have to use .length
to get the last letter.');"
+ "text": "你需要使用.length
获取最后一个字符",
+ "testString": "assert(code.match(/\\.length/g).length === 2, '你需要使用.length
获取最后一个字符');"
}
],
"challengeType": 1,
@@ -1697,14 +1697,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstName = \"Ada\";",
"var lastLetterOfFirstName = firstName[firstName.length - 1];",
"",
- "// Setup",
+ "// 初始化变量",
"var lastName = \"Lovelace\";",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var lastLetterOfLastName = lastName;",
"",
""
@@ -1720,23 +1720,23 @@
"id": "bd7123c9c452eddfaeb5bdef",
"title": "Use Bracket Notation to Find the Nth-to-Last Character in a String",
"description": [
- "You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character.",
- "For example, you can get the value of the third-to-last letter of the var firstName = \"Charles\"
string by using firstName[firstName.length - 3]
",
+ "我们既可以获取字符串的最后一个字符,也可以用获取字符串的倒数第N个字符。",
+ "例如,你可以这样firstName[firstName.length - 3]
操作来获得var firstName = \"Charles\"
字符串中的倒数第三个字符。",
"
",
- "Use bracket notation to find the second-to-last character in the lastName
string.",
- "Hint
Try looking at the thirdToLastLetterOfFirstName
variable declaration if you get stuck."
+ "使用方括号来获得lastName
字符串中的倒数第二个字符。",
+ "提示
如果你遇到困难了,不妨看看thirdToLastLetterOfFirstName
变量是如何做到的。"
],
"solutions": [
"var firstName = \"Ada\";\nvar thirdToLastLetterOfFirstName = firstName[firstName.length - 3];\n\nvar lastName = \"Lovelace\";\nvar secondToLastLetterOfLastName = lastName[lastName.length - 2];"
],
"tests": [
{
- "text": "secondToLastLetterOfLastName
should be \"c\".",
- "testString": "assert(secondToLastLetterOfLastName === 'c', 'secondToLastLetterOfLastName
should be \"c\".');"
+ "text": "secondToLastLetterOfLastName
应该是\"c\".",
+ "testString": "assert(secondToLastLetterOfLastName === 'c', 'secondToLastLetterOfLastName
应该是\"c\".');"
},
{
- "text": "You have to use .length
to get the second last letter.",
- "testString": "assert(code.match(/\\.length/g).length === 2, 'You have to use .length
to get the second last letter.');"
+ "text": "你需要使用.length
获取倒数第二个字符",
+ "testString": "assert(code.match(/\\.length/g).length === 2, '你需要使用.length
获取倒数第二个字符');"
}
],
"challengeType": 1,
@@ -1746,14 +1746,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var firstName = \"Ada\";",
"var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];",
"",
- "// Setup",
+ "// 初始化变量",
"var lastName = \"Lovelace\";",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"var secondToLastLetterOfLastName = lastName;",
"",
""
@@ -1769,14 +1769,14 @@
"id": "56533eb9ac21ba0edf2244bb",
"title": "Word Blanks",
"description": [
- "We will now use our knowledge of strings to build a \"Mad Libs\" style word game we're calling \"Word Blanks\". You will create an (optionally humorous) \"Fill in the Blanks\" style sentence.",
- "In a \"Mad Libs\" game, you are provided sentences with some missing words, like nouns, verbs, adjectives and adverbs. You then fill in the missing pieces with words of your choice in a way that the completed sentence makes sense.",
- "Consider this sentence - \"It was really ____, and we ____ ourselves ____\". This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows:",
+ "现在,我们来用字符串的相关知识实现一个 \"Mad Libs\" 类的文字游戏,称为 \"Word Blanks\"。 你将创建一个(可选幽默的)“填空”样式句子。",
+ "在 \"Mad Libs\" 游戏中,提供一个缺少一些单词的句子,缺少的单词包括名词,动词,形容词和副词等。然后,你选择一些单词填写句子缺失的地方,使句子完整并且有意义。",
+ "思考一下这句话 - \"It was really ____, and we ____ ourselves ____\"。这句话有三个缺失的部分 - 形容词,动词和副词,选择合适单词填入完成它。然后将完成的句子赋值给变量,如下所示:",
"var sentence = \"It was really\" + \"hot\" + \", and we\" + \"laughed\" + \"ourselves\" + \"silly.\";
",
"
",
- "In this challenge, we provide you with a noun, a verb, an adjective and an adverb. You need to form a complete sentence using words of your choice, along with the words we provide.",
- "You will need to use the string concatenation operator +
to build a new string, using the provided variables: myNoun
, myAdjective
, myVerb
, and myAdverb
. You will then assign the formed string to the result
variable.",
- "You will also need to account for spaces in your string, so that the final sentence has spaces between all the words. The result should be a complete sentence."
+ "在这个挑战中,我们为你提供名词,动词,形容词和副词。你需要使用合适单词以及我们提供的单词来形成完整的句子。",
+ "你需要使用字符串连接运算符+
来拼接字符串变量:myNoun
,myAdjective
,myVerb
,和myAdverb
来构建一个新字符串。然后,将新字符串赋给result
变量。",
+ "你还需要考虑字符串中的空格,确保句子的所有单词之间有空格。结果应该是一个完整的句子。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -1784,16 +1784,16 @@
],
"tests": [
{
- "text": "wordBlanks(\"\",\"\",\"\",\"\")
should return a string.",
- "testString": "assert(typeof wordBlanks(\"\",\"\",\"\",\"\") === 'string', 'wordBlanks(\"\",\"\",\"\",\"\")
should return a string.');"
+ "text": "wordBlanks(\"\",\"\",\"\",\"\")
应该返回一个字符串",
+ "testString": "assert(typeof wordBlanks(\"\",\"\",\"\",\"\") === 'string', 'wordBlanks(\"\",\"\",\"\",\"\")
应该返回一个字符串');"
},
{
- "text": "wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).",
- "testString": "assert(/\\bdog\\b/.test(test1) && /\\bbig\\b/.test(test1) && /\\bran\\b/.test(test1) && /\\bquickly\\b/.test(test1),'wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).');"
+ "text": "wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
应包含由非单词字符(以及 madlib 中的其他单词)分隔的所有传入的单词。",
+ "testString": "assert(/\\bdog\\b/.test(test1) && /\\bbig\\b/.test(test1) && /\\bran\\b/.test(test1) && /\\bquickly\\b/.test(test1),'wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
应包含由非单词字符(以及 madlib 中的其他单词)分隔的所有传入的单词。');"
},
{
- "text": "wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).",
- "testString": "assert(/\\bcat\\b/.test(test2) && /\\blittle\\b/.test(test2) && /\\bhit\\b/.test(test2) && /\\bslowly\\b/.test(test2),'wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).');"
+ "text": "wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
应包含由非单词字符(以及 madlib 中的其他单词)分隔的所有传入的单词。",
+ "testString": "assert(/\\bcat\\b/.test(test2) && /\\blittle\\b/.test(test2) && /\\bhit\\b/.test(test2) && /\\bslowly\\b/.test(test2),'wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
应包含由非单词字符(以及 madlib 中的其他单词)分隔的所有传入的单词。');"
}
],
"challengeType": 1,
@@ -1804,14 +1804,14 @@
"name": "index",
"contents": [
"function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {",
- " // Your code below this line",
+ " // 请把你的代码写在这条注释以下",
" var result = \"\";",
"",
- " // Your code above this line",
+ " // 请把你的代码写在这条注释以上",
" return result;",
"}",
"",
- "// Change the words here to test your function",
+ "// 修改单词来测试函数",
"wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\");"
],
"head": [],
@@ -1826,28 +1826,28 @@
"id": "bd7993c9c69feddfaeb8bdef",
"title": "Store Multiple Values in one Variable using JavaScript Arrays",
"description": [
- "With JavaScript array
variables, we can store several pieces of data in one place.",
- "You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this: ",
+ "使用数组
,我们可以在一个地方存储多个数据。",
+ "以左方括号[
开始定义一个数组,以右方括号]
结束,里面每个元素之间用逗号隔开,例如:",
"var sandwich = [\"peanut butter\", \"jelly\", \"bread\"]
.",
"
",
- "Modify the new array myArray
so that it contains both a string
and a number
(in that order).",
- "Hint
Refer to the example code in the text editor if you get stuck."
+ "创建一个包含字符串
和数字
的数组myArray
。",
+ "提示
如果你遇到困难,请参考文本编辑器中的示例代码。"
],
"solutions": [
"var myArray = [\"The Answer\", 42];"
],
"tests": [
{
- "text": "myArray
should be an array
.",
- "testString": "assert(typeof myArray == 'object', 'myArray
should be an array
.');"
+ "text": "myArray
应该是一个数组
",
+ "testString": "assert(typeof myArray == 'object', 'myArray
应该是一个数组
');"
},
{
- "text": "The first item in myArray
should be a string
.",
- "testString": "assert(typeof myArray[0] !== 'undefined' && typeof myArray[0] == 'string', 'The first item in myArray
should be a string
.');"
+ "text": "myArray
数组的第一个元素应该是一个字符串
",
+ "testString": "assert(typeof myArray[0] !== 'undefined' && typeof myArray[0] == 'string', 'myArray
数组的第一个元素应该是一个字符串
');"
},
{
- "text": "The second item in myArray
should be a number
.",
- "testString": "assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number', 'The second item in myArray
should be a number
.');"
+ "text": "myArray
数组的第二个元素应该是一个数字
",
+ "testString": "assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number', 'myArray
数组的第二个元素应该是一个数字
');"
}
],
"challengeType": 1,
@@ -1857,10 +1857,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [\"John\", 23];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var myArray = [];",
""
],
@@ -1875,17 +1875,17 @@
"id": "cf1111c1c11feddfaeb7bdef",
"title": "Nest one Array within Another Array",
"description": [
- "You can also nest arrays within other arrays, like this: [[\"Bulls\", 23], [\"White Sox\", 45]]
. This is also called a Multi-dimensional Array.",
+ "你也可以在数组中包含其他数组,例如:[[\"Bulls\", 23], [\"White Sox\", 45]]
。这被称为一个多维数组。",
"
",
- "Create a nested array called myArray
."
+ "创建一个名为myArray
的多维数组。"
],
"solutions": [
"var myArray = [[1,2,3]];"
],
"tests": [
{
- "text": "myArray
should have at least one array nested within another array.",
- "testString": "assert(Array.isArray(myArray) && myArray.some(Array.isArray), 'myArray
should have at least one array nested within another array.');"
+ "text": "应该包含至少一个嵌入的数组",
+ "testString": "assert(Array.isArray(myArray) && myArray.some(Array.isArray), '应该包含至少一个嵌入的数组');"
}
],
"challengeType": 1,
@@ -1895,10 +1895,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [[\"the universe\", 42], [\"everything\", 101010]];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var myArray = [];",
""
],
@@ -1913,25 +1913,25 @@
"id": "56bbb991ad1ed5201cd392ca",
"title": "Access Array Data with Indexes",
"description": [
- "We can access the data inside arrays using indexes
.",
- "Array indexes are written in the same bracket notation that strings use, except that instead of specifying a character, they are specifying an entry in the array. Like strings, arrays use zero-based indexing, so the first element in an array is element 0
.",
- "Example",
+ "我们可以像操作字符串一样通过数组索引[index]
来访问数组中的数据。",
+ "数组索引的使用与字符串索引一样,不同的是,通过字符串的索引得到的是一个字符,通过数组索引得到的是一个元素。与字符串类似,数组也是基于零的索引,因此数组的第一个元素的索引是0
。",
+ "示例",
"var array = [50,60,70];
array[0]; // equals 50
var data = array[1]; // equals 60
",
- "Note
There shouldn't be any spaces between the array name and the square brackets, like array [0]
. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
+ "提示
数组名称和方括号之间不应有任何空格,如array [0]
尽管 JavaScript 能够正确处理,但可能会让看你代码的其他程序员感到困惑",
"
",
- "Create a variable called myData
and set it to equal the first value of myArray
using bracket notation."
+ "创建一个名为myData
的变量,并把myArray
的第一个索引上的值赋给它。"
],
"solutions": [
"var myArray = [50,60,70];\nvar myData = myArray[0];"
],
"tests": [
{
- "text": "The variable myData
should equal the first value of myArray
.",
- "testString": "assert((function(){if(typeof myArray !== 'undefined' && typeof myData !== 'undefined' && myArray[0] === myData){return true;}else{return false;}})(), 'The variable myData
should equal the first value of myArray
.');"
+ "text": "变量myData
的值应该等于myArray
的第一个值",
+ "testString": "assert((function(){if(typeof myArray !== 'undefined' && typeof myData !== 'undefined' && myArray[0] === myData){return true;}else{return false;}})(), '变量myData
的值应该等于myArray
的第一个值');"
},
{
- "text": "The data in variable myArray
should be accessed using bracket notation.",
- "testString": "assert((function(){if(code.match(/\\s*=\\s*myArray\\[0\\]/g)){return true;}else{return false;}})(), 'The data in variable myArray
should be accessed using bracket notation.');"
+ "text": "应使用方括号访问变量myArray
中的数据",
+ "testString": "assert((function(){if(code.match(/\\s*=\\s*myArray\\[0\\]/g)){return true;}else{return false;}})(), '应使用方括号访问变量myArray
中的数据');"
}
],
"challengeType": 1,
@@ -1942,14 +1942,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [50,60,70];",
"var ourData = ourArray[0]; // equals 50",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [50,60,70];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
""
],
"head": [],
@@ -1963,24 +1963,24 @@
"id": "cf1111c1c11feddfaeb8bdef",
"title": "Modify Array Data With Indexes",
"description": [
- "Unlike strings, the entries of arrays are mutable and can be changed freely.",
- "Example",
- "var ourArray = [50,40,30];
ourArray[0] = 15; // equals [15,40,30]
",
- "Note
There shouldn't be any spaces between the array name and the square brackets, like array [0]
. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
+ "与字符串的数据不可变不同,数组的数据是可变的,并且可以自由地改变。",
+ "示例",
+ "var ourArray = [50,40,30];
ourArray[0] = 15; // 等于 [15,40,30]
",
+ "提示
数组名称和方括号之间不应有任何空格,如array [0]
尽管 JavaScript 能够正确处理,但可能会让看你代码的其他程序员感到困惑。",
"
",
- "Modify the data stored at index 0
of myArray
to a value of 45
."
+ "修改数组myArray
中索引0上的值为45
。"
],
"solutions": [
"var myArray = [18,64,99];\nmyArray[0] = 45;"
],
"tests": [
{
- "text": "myArray
should now be [45,64,99].",
- "testString": "assert((function(){if(typeof myArray != 'undefined' && myArray[0] == 45 && myArray[1] == 64 && myArray[2] == 99){return true;}else{return false;}})(), 'myArray
should now be [45,64,99].');"
+ "text": "myArray
的值应该 [45,64,99]",
+ "testString": "assert((function(){if(typeof myArray != 'undefined' && myArray[0] == 45 && myArray[1] == 64 && myArray[2] == 99){return true;}else{return false;}})(), 'myArray
的值应该 [45,64,99]');"
},
{
- "text": "You should be using correct index to modify the value in myArray
.",
- "testString": "assert((function(){if(code.match(/myArray\\[0\\]\\s*=\\s*/g)){return true;}else{return false;}})(), 'You should be using correct index to modify the value in myArray
.');"
+ "text": "你应该使用正确的索引修改myArray
的值",
+ "testString": "assert((function(){if(code.match(/myArray\\[0\\]\\s*=\\s*/g)){return true;}else{return false;}})(), '你应该使用正确的索引修改myArray
的值');"
}
],
"challengeType": 1,
@@ -1990,14 +1990,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [18,64,99];",
"ourArray[1] = 45; // ourArray now equals [18,45,99].",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [18,64,99];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -2012,12 +2012,12 @@
"id": "56592a60ddddeae28f7aa8e1",
"title": "Access Multi-Dimensional Arrays With Indexes",
"description": [
- "One way to think of a multi-dimensional array, is as an array of arrays. When you use brackets to access your array, the first set of brackets refers to the entries in the outer-most (the first level) array, and each additional pair of brackets refers to the next level of entries inside.",
- "Example",
- "var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // equals [[10,11,12], 13, 14]
arr[3][0]; // equals [10,11,12]
arr[3][0][1]; // equals 11
",
- "Note
There shouldn't be any spaces between the array name and the square brackets, like array [0][0]
and even this array [0] [0]
is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
+ "可以把 多维 数组看作成是一个 数组中的数组。当使用方括号去访问数组的时候,第一个[index]
访问的是第 N 个子数组,第二个[index]
访问的是第 N 个子数组的第N个元素。",
+ "示例",
+ "var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // 等于 [[10,11,12], 13, 14]
arr[3][0]; // 等于 [10,11,12]
arr[3][0][1]; // 等于 11
",
+ "提示
T数组名称和方括号之间不应该有任何空格,如array [0][0]
甚至是这样array [0] [0]
尽管 JavaScript 能够正确处理,但可能会让看你代码的其他程序员感到困惑。",
"
",
- "Using bracket notation select an element from myArray
such that myData
is equal to 8
."
+ "使用恰当的[index]
访问myArray
,使得myData
的值为8
"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2025,12 +2025,12 @@
],
"tests": [
{
- "text": "myData
should be equal to 8
.",
- "testString": "assert(myData === 8, 'myData
should be equal to 8
.');"
+ "text": "myData
应该等于8
.",
+ "testString": "assert(myData === 8, 'myData
应该等于8
.');"
},
{
- "text": "You should be using bracket notation to read the correct value from myArray
.",
- "testString": "assert(/myArray\\[2\\]\\[1\\]/g.test(code) && !/myData\\s*=\\s*(?:.*[-+*/%]|\\d)/g.test(code), 'You should be using bracket notation to read the correct value from myArray
.');"
+ "text": "你应该使用方括号从myArray
中取值",
+ "testString": "assert(/myArray\\[2\\]\\[1\\]/g.test(code) && !/myData\\s*=\\s*(?:.*[-+*/%]|\\d)/g.test(code), '你应该使用方括号从myArray
中取值');"
}
],
"challengeType": 1,
@@ -2041,10 +2041,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var myData = myArray[0][0];",
""
],
@@ -2059,19 +2059,19 @@
"id": "56bbb991ad1ed5201cd392cb",
"title": "Manipulate Arrays With push()",
"description": [
- "An easy way to append data to the end of an array is via the push()
function.",
- ".push()
takes one or more parameters and \"pushes\" them onto the end of the array.",
- "var arr = [1,2,3];
arr.push(4);
// arr is now [1,2,3,4]
",
+ "一个简单的方法将数据添加到一个数组的末尾是通过push()
函数。",
+ ".push()
接受把一个或多个参数,并把它“推”入到数组的末尾。",
+ "var arr = [1,2,3];
arr.push(4);
// 现在arr的值为 [1,2,3,4]
",
"
",
- "Push [\"dog\", 3]
onto the end of the myArray
variable."
+ "把[\"dog\", 3]
“推”入到myArray
变量的末尾。"
],
"solutions": [
"var myArray = [[\"John\", 23], [\"cat\", 2]];\nmyArray.push([\"dog\",3]);"
],
"tests": [
{
- "text": "myArray
should now equal [[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.",
- "testString": "assert((function(d){if(d[2] != undefined && d[0][0] == 'John' && d[0][1] === 23 && d[2][0] == 'dog' && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray), 'myArray
should now equal [[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.');"
+ "text": "myArray
应该等于[[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.",
+ "testString": "assert((function(d){if(d[2] != undefined && d[0][0] == 'John' && d[0][1] === 23 && d[2][0] == 'dog' && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray), 'myArray
应该等于[[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.');"
}
],
"challengeType": 1,
@@ -2081,15 +2081,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [\"Stimpson\", \"J\", \"cat\"];",
"ourArray.push([\"happy\", \"joy\"]); ",
- "// ourArray now equals [\"Stimpson\", \"J\", \"cat\", [\"happy\", \"joy\"]]",
+ "// 经过 push 操作后,ourArray 的值为 [\"Stimpson\", \"J\", \"cat\", [\"happy\", \"joy\"]]",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [[\"John\", 23], [\"cat\", 2]];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -2104,28 +2104,28 @@
"id": "56bbb991ad1ed5201cd392cc",
"title": "Manipulate Arrays With pop()",
"description": [
- "Another way to change the data in an array is with the .pop()
function.",
- ".pop()
is used to \"pop\" a value off of the end of an array. We can store this \"popped off\" value by assigning it to a variable. In other words, .pop()
removes the last element from an array and returns that element.",
- "Any type of entry can be \"popped\" off of an array - numbers, strings, even nested arrays.",
- "var threeArr = [1, 4, 6];
var oneDown = threeArr.pop();
console.log(oneDown); // Returns 6
console.log(threeArr); // Returns [1, 4]
",
+ "改变数组中数据的另一种方法是用.pop()
函数。",
+ ".pop()
函数用来“抛出”一个数组末尾的值。我们可以把这个“抛出”的值赋给一个变量存储起来。换句话说就是.pop()
函数移除数组末尾的元素并返回这个元素。",
+ "数组中任何类型的元素(数值,字符串,甚至是数组)可以被“抛出来” 。",
+ "var oneDown = [1, 4, 6].pop();
console.log(oneDown); // 返回 6
console.log(threeArr); // 返回的值为6
,数组变成了[1, 4]
。",
"
",
- "Use the .pop()
function to remove the last item from myArray
, assigning the \"popped off\" value to removedFromMyArray
."
+ "使用.pop()
函数移除myArray
中的最后一个元素,并且把“抛出”的值赋给removedFromMyArray
。"
],
"solutions": [
"var myArray = [[\"John\", 23], [\"cat\", 2]];\nvar removedFromMyArray = myArray.pop();"
],
"tests": [
{
- "text": "myArray
should only contain [[\"John\", 23]]
.",
- "testString": "assert((function(d){if(d[0][0] == 'John' && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray), 'myArray
should only contain [[\"John\", 23]]
.');"
+ "text": "myArray
应该只包含[[\"John\", 23]]
.",
+ "testString": "assert((function(d){if(d[0][0] == 'John' && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray), 'myArray
应该只包含[[\"John\", 23]]
.');"
},
{
- "text": "Use pop()
on myArray
",
- "testString": "assert(/removedFromMyArray\\s*=\\s*myArray\\s*.\\s*pop\\s*(\\s*)/.test(code), 'Use pop()
on myArray
');"
+ "text": "对myArray
使用pop()
函数 ",
+ "testString": "assert(/removedFromMyArray\\s*=\\s*myArray\\s*.\\s*pop\\s*(\\s*)/.test(code), '对myArray
使用pop()
函数 ');"
},
{
- "text": "removedFromMyArray
should only contain [\"cat\", 2]
.",
- "testString": "assert((function(d){if(d[0] == 'cat' && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), 'removedFromMyArray
should only contain [\"cat\", 2]
.');"
+ "text": "removedFromMyArray
应该只包含[\"cat\", 2]
.",
+ "testString": "assert((function(d){if(d[0] == 'cat' && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), 'removedFromMyArray
应该只包含[\"cat\", 2]
.');"
}
],
"challengeType": 1,
@@ -2135,15 +2135,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [1,2,3];",
"var removedFromOurArray = ourArray.pop(); ",
- "// removedFromOurArray now equals 3, and ourArray now equals [1,2]",
+ "// 经过 pop 操作之后,removedFromOurArray 的值为 3,ourArray 的值为 [1,2]",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [[\"John\", 23], [\"cat\", 2]];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var removedFromMyArray;",
"",
""
@@ -2159,22 +2159,22 @@
"id": "56bbb991ad1ed5201cd392cd",
"title": "Manipulate Arrays With shift()",
"description": [
- "pop()
always removes the last element of an array. What if you want to remove the first?",
- "That's where .shift()
comes in. It works just like .pop()
, except it removes the first element instead of the last.",
+ "pop()
函数用来移出数组中最后一个元素。如果想要移出第一个元素要怎么办呢?",
+ "这就是.shift()
的用武之地。它的工作原理就像.pop()
,但它移除的是第一个元素,而不是最后一个。",
"
",
- "Use the .shift()
function to remove the first item from myArray
, assigning the \"shifted off\" value to removedFromMyArray
."
+ "使用.shift()
函数移出myArray
中的第一项,并把“移出”的值赋给removedFromMyArray
。"
],
"solutions": [
- "var myArray = [[\"John\", 23], [\"dog\", 3]];\n\n// Only change code below this line.\nvar removedFromMyArray = myArray.shift();"
+ "var myArray = [[\"John\", 23], [\"dog\", 3]];\n\n// 请把你的代码写在这条注释以下\nvar removedFromMyArray = myArray.shift();"
],
"tests": [
{
- "text": "myArray
should now equal [[\"dog\", 3]]
.",
- "testString": "assert((function(d){if(d[0][0] == 'dog' && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray), 'myArray
should now equal [[\"dog\", 3]]
.');"
+ "text": "myArray
应该等于[[\"dog\", 3]]
.",
+ "testString": "assert((function(d){if(d[0][0] == 'dog' && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray), 'myArray
应该等于[[\"dog\", 3]]
.');"
},
{
- "text": "removedFromMyArray
should contain [\"John\", 23]
.",
- "testString": "assert((function(d){if(d[0] == 'John' && d[1] === 23 && typeof removedFromMyArray === 'object'){return true;}else{return false;}})(removedFromMyArray), 'removedFromMyArray
should contain [\"John\", 23]
.');"
+ "text": "removedFromMyArray
应该包含[\"John\", 23]
.",
+ "testString": "assert((function(d){if(d[0] == 'John' && d[1] === 23 && typeof removedFromMyArray === 'object'){return true;}else{return false;}})(removedFromMyArray), 'removedFromMyArray
应该包含[\"John\", 23]
.');"
}
],
"challengeType": 1,
@@ -2184,15 +2184,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [\"Stimpson\", \"J\", [\"cat\"]];",
"var removedFromOurArray = ourArray.shift();",
"// removedFromOurArray now equals \"Stimpson\" and ourArray now equals [\"J\", [\"cat\"]].",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [[\"John\", 23], [\"dog\", 3]];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"var removedFromMyArray;",
"",
""
@@ -2208,18 +2208,18 @@
"id": "56bbb991ad1ed5201cd392ce",
"title": "Manipulate Arrays With unshift()",
"description": [
- "Not only can you shift
elements off of the beginning of an array, you can also unshift
elements to the beginning of an array i.e. add elements in front of the array.",
- ".unshift()
works exactly like .push()
, but instead of adding the element at the end of the array, unshift()
adds the element at the beginning of the array.",
+ "你不仅可以shift
(移出)数组中的第一个元素,你也可以unshift
(移入)一个元素到数组的头部。",
+ ".unshift()
函数用起来就像.push()
函数一样, 但不是在数组的末尾添加元素,而是在数组的头部添加元素。",
"
",
- "Add [\"Paul\",35]
to the beginning of the myArray
variable using unshift()
."
+ "使用unshift()
函数把[\"Paul\",35]
加入到myArray
的头部。"
],
"solutions": [
"var myArray = [[\"John\", 23], [\"dog\", 3]];\nmyArray.shift();\nmyArray.unshift([\"Paul\", 35]);"
],
"tests": [
{
- "text": "myArray
should now have [[\"Paul\", 35], [\"dog\", 3]].",
- "testString": "assert((function(d){if(typeof d[0] === \"object\" && d[0][0] == 'Paul' && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), 'myArray
should now have [[\"Paul\", 35], [\"dog\", 3]].');"
+ "text": "myArray
应该包含[[\"Paul\", 35], [\"dog\", 3]].",
+ "testString": "assert((function(d){if(typeof d[0] === \"object\" && d[0][0] == 'Paul' && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), 'myArray
应该包含[[\"Paul\", 35], [\"dog\", 3]].');"
}
],
"challengeType": 1,
@@ -2229,17 +2229,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [\"Stimpson\", \"J\", \"cat\"];",
- "ourArray.shift(); // ourArray now equals [\"J\", \"cat\"]",
+ "ourArray.shift(); // 经过 shift 操作后,ourArray 的值为 [\"J\", \"cat\"]",
"ourArray.unshift(\"Happy\"); ",
- "// ourArray now equals [\"Happy\", \"J\", \"cat\"]",
+ "// 经过 unshift 操作后,ourArray 的值为 [\"Happy\", \"J\", \"cat\"]",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [[\"John\", 23], [\"dog\", 3]];",
"myArray.shift();",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -2254,10 +2254,10 @@
"id": "56533eb9ac21ba0edf2244bc",
"title": "Shopping List",
"description": [
- "Create a shopping list in the variable myList
. The list should be a multi-dimensional array containing several sub-arrays.",
- "The first element in each sub-array should contain a string with the name of the item. The second element should be a number representing the quantity i.e.",
+ "创建一个名叫myList
的购物清单,清单的数据格式就是多维数组。",
+ "每个子数组中的第一个元素应该是购买的物品名称,第二个元素应该是物品的数量,类似于:",
"[\"Chocolate Bar\", 15]
",
- "There should be at least 5 sub-arrays in the list."
+ "任务:你的购物清单至少应该有 5 个子数组。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2265,20 +2265,20 @@
],
"tests": [
{
- "text": "myList
should be an array",
- "testString": "assert(isArray, 'myList
should be an array');"
+ "text": "myList
应该一个数组",
+ "testString": "assert(isArray, 'myList
应该一个数组');"
},
{
- "text": "The first elements in each of your sub-arrays must all be strings",
- "testString": "assert(hasString, 'The first elements in each of your sub-arrays must all be strings');"
+ "text": "你的每个子数组的第一个元素的类型都应该是字符串",
+ "testString": "assert(hasString, '你的每个子数组的第一个元素的类型都应该是字符串');"
},
{
- "text": "The second elements in each of your sub-arrays must all be numbers",
- "testString": "assert(hasNumber, 'The second elements in each of your sub-arrays must all be numbers');"
+ "text": "你的每个子数组的第二个元素的类型都应该是字符串",
+ "testString": "assert(hasNumber, '你的每个子数组的第二个元素的类型都应该是字符串');"
},
{
- "text": "You must have at least 5 items in your list",
- "testString": "assert(count > 4, 'You must have at least 5 items in your list');"
+ "text": "你的列表中至少要包含 5 个元素",
+ "testString": "assert(count > 4, '你的列表中至少要包含 5 个元素');"
}
],
"challengeType": 1,
@@ -2328,30 +2328,30 @@
"id": "56bbb991ad1ed5201cd392cf",
"title": "Write Reusable JavaScript with Functions",
"description": [
- "In JavaScript, we can divide up our code into reusable parts called functions.",
- "Here's an example of a function:",
- "function functionName() {
console.log(\"Hello World\");
}
",
- "You can call or invoke this function by using its name followed by parentheses, like this:",
+ "在 JavaScript 中,我们可以把代码的重复部分抽取出来,放到一个函数(functions)中。",
+ "这是一个函数(function)的例子:",
+ "function functionName() {
console.log(\"Hello World\");
}
",
+ "你可以通过函数名称functionName
加上后面的小括号来调用这个函数(function),就像这样:",
"functionName();
",
- "Each time the function is called it will print out the message \"Hello World\"
on the dev console. All of the code between the curly braces will be executed every time the function is called.",
+ "每次调用函数时它会打印出消息“Hello World”到开发的控制台上。所有的大括号之间的代码将在每次函数调用时执行。",
"
",
- "- Create a function called
reusableFunction
which prints \"Hi World\"
to the dev console. - Call the function.
"
+ "- 创建一个名为
myFunction
的函数,这个函数可以打印“Hi World”到开发控制台上。 - 调用这个函数。
"
],
"solutions": [
"function reusableFunction() {\n console.log(\"Hi World\");\n}\nreusableFunction();"
],
"tests": [
{
- "text": "reusableFunction
should be a function",
- "testString": "assert(typeof reusableFunction === 'function', 'reusableFunction
should be a function');"
+ "text": "myFunction
应该是一个函数",
+ "testString": "assert(typeof reusableFunction === 'function', 'myFunction
应该是一个函数');"
},
{
- "text": "reusableFunction
should output \"Hi World\" to the dev console",
- "testString": "assert(\"Hi World\" === logOutput, 'reusableFunction
should output \"Hi World\" to the dev console');"
+ "text": "myFunction
应该在控制台中输出 \"Hi World\"",
+ "testString": "assert(\"Hi World\" === logOutput, 'myFunction
应该在控制台中输出 \"Hi World\"');"
},
{
- "text": "Call reusableFunction
after you define it",
- "testString": "assert(/^\\s*reusableFunction\\(\\)\\s*;/m.test(code), 'Call reusableFunction
after you define it');"
+ "text": "在你定义myFunction
之后记得调用它",
+ "testString": "assert(/^\\s*reusableFunction\\(\\)\\s*;/m.test(code), '在你定义myFunction
之后记得调用它');"
}
],
"challengeType": 1,
@@ -2361,14 +2361,14 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"function ourReusableFunction() {",
" console.log(\"Heyya, World\");",
"}",
"",
"ourReusableFunction();",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
""
],
"head": [
@@ -2409,14 +2409,14 @@
"id": "56533eb9ac21ba0edf2244bd",
"title": "Passing Values to Functions with Arguments",
"description": [
- "Parameters are variables that act as placeholders for the values that are to be input to a function when it is called. When a function is defined, it is typically defined along with one or more parameters. The actual values that are input (or \"passed\") into a function when it is called are known as arguments.",
- "Here is a function with two parameters, param1
and param2
:",
- "function testFun(param1, param2) {
console.log(param1, param2);
}
",
- "Then we can call testFun
:",
+ "函数的参数parameters
在函数中充当占位符(也叫形参)的作用,参数可以为一个或多个。调用一个函数时所传入的参数为实参,实参决定着形参真正的值。简单理解:形参即形式、实参即内容。",
+ "这是带有两个参数的函数,param1
和param2
:",
+ "function testFun(param1, param2) {
console.log(param1, param2);
}
",
+ "接着我们调用testFun
:",
"testFun(\"Hello\", \"World\");
",
- "We have passed two arguments, \"Hello\"
and \"World\"
. Inside the function, param1
will equal \"Hello\" and param2
will equal \"World\". Note that you could call testFun
again with different arguments and the parameters would take on the value of the new arguments.",
+ "我们传递了两个参数,\"Hello\"
和\"World\"
。在函数内部,param1
等于“Hello”,param2
等于“World”。请注意,testFun
函数可以多次调用,每次调用时传递的参数会决定形参的实际值。",
"
",
- "- Create a function called
functionWithArgs
that accepts two arguments and outputs their sum to the dev console. - Call the function with two numbers as arguments.
"
+ "- 创建一个名为
myFunction
的函数,它可以接收两个参数,计算参数的和,将结果输出到控制台。 - 调用这个函数。
"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2424,20 +2424,20 @@
],
"tests": [
{
- "text": "functionWithArgs
should be a function",
- "testString": "assert(typeof functionWithArgs === 'function', 'functionWithArgs
should be a function');"
+ "text": "functionWithArgs
应该是一个函数",
+ "testString": "assert(typeof functionWithArgs === 'function', 'functionWithArgs
应该是一个函数');"
},
{
- "text": "functionWithArgs(1,2)
should output 3
",
- "testString": "if(typeof functionWithArgs === \"function\") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, 'functionWithArgs(1,2)
should output 3
');"
+ "text": "functionWithArgs(1,2)
应该输出3
",
+ "testString": "if(typeof functionWithArgs === \"function\") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, 'functionWithArgs(1,2)
应该输出3
');"
},
{
- "text": "functionWithArgs(7,9)
should output 16
",
- "testString": "if(typeof functionWithArgs === \"function\") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, 'functionWithArgs(7,9)
should output 16
');"
+ "text": "functionWithArgs(7,9)
应该输出16
",
+ "testString": "if(typeof functionWithArgs === \"function\") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, 'functionWithArgs(7,9)
应该输出16
');"
},
{
- "text": "Call functionWithArgs
with two numbers after you define it.",
- "testString": "assert(/^\\s*functionWithArgs\\s*\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)\\s*;/m.test(code), 'Call functionWithArgs
with two numbers after you define it.');"
+ "text": "在你定义myFunction
之后记得调用它",
+ "testString": "assert(/^\\s*functionWithArgs\\s*\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)\\s*;/m.test(code), '在你定义myFunction
之后记得调用它');"
}
],
"challengeType": 1,
@@ -2447,13 +2447,13 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"function ourFunctionWithArgs(a, b) {",
" console.log(a - b);",
"}",
"ourFunctionWithArgs(10, 5); // Outputs 5",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -2495,15 +2495,15 @@
"id": "56533eb9ac21ba0edf2244be",
"title": "Global Scope and Functions",
"description": [
- "In JavaScript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope. This means, they can be seen everywhere in your JavaScript code.",
- "Variables which are used without the var
keyword are automatically created in the global
scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var
.",
+ "在 JavaScript 中,作用域涉及到变量的作用范围。在函数外定义的变量具有 全局 作用域。这意味着,具有全局作用域的变量可以在代码的任何地方被调用。",
+ "这些没有使用var
关键字定义的变量,会被自动创建在全局作用域中,形成全局变量。当在代码其他地方无意间定义了一个变量,刚好变量名与全局变量相同,这时会产生意想不到的后果。因此你应该总是使用var关键字来声明你的变量。",
"
",
- "Using var
, declare a global
variable myGlobal
outside of any function. Initialize it with a value of 10
.",
- "Inside function fun1
, assign 5
to oopsGlobal
without using the var
keyword."
+ "在函数外声明一个全局
变量myGlobal
,并给它一个初始值10
",
+ "在函数fun1
的内部,不使用var
关键字来声明oopsGlobal
,并赋值为5
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "// Declare your variable here\nvar myGlobal = 10;\n\nfunction fun1() {\n // Assign 5 to oopsGlobal Here\n oopsGlobal = 5;\n}\n\n// Only change code above this line\nfunction fun2() {\n var output = \"\";\n if(typeof myGlobal != \"undefined\") {\n output += \"myGlobal: \" + myGlobal;\n }\n if(typeof oopsGlobal != \"undefined\") {\n output += \" oopsGlobal: \" + oopsGlobal;\n }\n console.log(output);\n}"
+ "// Declare your variable here\nvar myGlobal = 10;\n\nfunction fun1() {\n // Assign 5 to oopsGlobal Here\n oopsGlobal = 5;\n}\n\n// 请把你的代码写在这条注释以上\nfunction fun2() {\n var output = \"\";\n if(typeof myGlobal != \"undefined\") {\n output += \"myGlobal: \" + myGlobal;\n }\n if(typeof oopsGlobal != \"undefined\") {\n output += \" oopsGlobal: \" + oopsGlobal;\n }\n console.log(output);\n}"
],
"tests": [
{
@@ -2530,15 +2530,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Declare your variable here",
+ "// 声明变量",
"",
"",
"function fun1() {",
- " // Assign 5 to oopsGlobal Here",
+ " // 把 5 赋给 oopsGlobal",
" ",
"}",
"",
- "// Only change code above this line",
+ "// 请把你的代码写在这条注释以上",
"function fun2() {",
" var output = \"\";",
" if (typeof myGlobal != \"undefined\") {",
@@ -2585,13 +2585,12 @@
"id": "56533eb9ac21ba0edf2244bf",
"title": "Local Scope and Functions",
"description": [
- "Variables which are declared within a function, as well as the function parameters have local scope. That means, they are only visible within that function.",
- "Here is a function myTest
with a local variable called loc
.",
- "function myTest() {
var loc = \"foo\";
console.log(loc);
}
myTest(); // logs \"foo\"
console.log(loc); // loc is not defined
",
- "loc
is not defined outside of the function.",
+ "在一个函数内声明的变量,以及该函数的参数都是局部变量,意味着它们只在该函数内可见。",
+ "这是在函数myTest
内声明局部变量loc
的例子:",
+ "function myTest() {
var loc = \"foo\";
console.log(loc);
}
myTest(); // 打印出 \"foo\"
console.log(loc); // loc 没有定义
",
+ "在函数外,loc
是未定义的。",
"
",
- "Declare a local variable myVar
inside myLocalScope
. Run the tests and then follow the instructions commented out in the editor.",
- "Hint
Refreshing the page may help if you get stuck."
+ "在函数myFunction
内部声明一个局部变量myVar
,并删除外部的 console.log。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2599,12 +2598,12 @@
],
"tests": [
{
- "text": "No global myVar
variable",
- "testString": "assert(typeof myVar === 'undefined', 'No global myVar
variable');"
+ "text": "未找到全局的myVar
变量",
+ "testString": "assert(typeof myVar === 'undefined', '未找到全局的myVar
变量');"
},
{
- "text": "Add a local myVar
variable",
- "testString": "assert(/var\\s+myVar/.test(code), 'Add a local myVar
variable');"
+ "text": "需要定义局部的myVar
变量",
+ "testString": "assert(/var\\s+myVar/.test(code), '需要定义局部的myVar
变量');"
}
],
"challengeType": 1,
@@ -2615,17 +2614,17 @@
"name": "index",
"contents": [
"function myLocalScope() {",
- " 'use strict'; // you shouldn't need to edit this line",
+ " 'use strict'; // 请不要修改这一行",
" ",
" console.log(myVar);",
"}",
"myLocalScope();",
"",
- "// Run and check the console",
- "// myVar is not defined outside of myLocalScope",
+ "// 请先运行这段代码,并在输出区域或浏览器的控制台中查看输出",
+ "// 由于 myVar 在 myLocalScope 内外均没有定义,因此才会有报错",
"console.log(myVar);",
"",
- "// Now remove the console log line to pass the test",
+ "// 现在,在 myLocalScope 中定义 myVar,并删掉 myLocalScope 外面的 console.log 以通过测试",
""
],
"head": [
@@ -2660,12 +2659,12 @@
"id": "56533eb9ac21ba0edf2244c0",
"title": "Global vs. Local Scope in Functions",
"description": [
- "It is possible to have both local and global variables with the same name. When you do this, the local
variable takes precedence over the global
variable.",
- "In this example:",
- "var someVar = \"Hat\";
function myFun() {
var someVar = \"Head\";
return someVar;
}
",
- "The function myFun
will return \"Head\"
because the local
version of the variable is present.",
+ "一个程序中有可能具有相同名称的局部变量 和全局变量。在这种情况下,局部
变量将会优先于全局
变量。",
+ "下面为例:",
+ "var someVar = \"Hat\";
function myFun() {
var someVar = \"Head\";
return someVar;
}
",
+ "函数myFun
将会返回\"Head\"
,因为局部变量
优先级更高。",
"
",
- "Add a local variable to myOutfit
function to override the value of outerWear
with \"sweater\"
."
+ "给myOutfit
添加一个局部变量来覆盖outerWear
的值为\"sweater\"
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2673,16 +2672,16 @@
],
"tests": [
{
- "text": "Do not change the value of the global outerWear
",
- "testString": "assert(outerWear === \"T-Shirt\", 'Do not change the value of the global outerWear
');"
+ "text": "不要修改全局变量outerWear
的值",
+ "testString": "assert(outerWear === \"T-Shirt\", '不要修改全局变量outerWear
的值');"
},
{
- "text": "myOutfit
should return \"sweater\"
",
- "testString": "assert(myOutfit() === \"sweater\", 'myOutfit
should return \"sweater\"
');"
+ "text": "myOutfit
应该返回\"sweater\"
",
+ "testString": "assert(myOutfit() === \"sweater\", 'myOutfit
应该返回\"sweater\"
');"
},
{
- "text": "Do not change the return statement",
- "testString": "assert(/return outerWear/.test(code), 'Do not change the return statement');"
+ "text": "不要修改return
语句",
+ "testString": "assert(/return outerWear/.test(code), '不要修改return
语句');"
}
],
"challengeType": 1,
@@ -2692,15 +2691,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var outerWear = \"T-Shirt\";",
"",
"function myOutfit() {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return outerWear;",
"}",
"",
@@ -2715,12 +2714,12 @@
"id": "56533eb9ac21ba0edf2244c2",
"title": "Return a Value from a Function with Return",
"description": [
- "We can pass values into a function with arguments. You can use a return
statement to send a value back out of a function.",
- "Example",
- "function plusThree(num) {
return num + 3;
}
var answer = plusThree(5); // 8
",
- "plusThree
takes an argument for num
and returns a value equal to num + 3
.",
+ "我们可以通过函数的参数把值传入函数,也可以使用return
语句把数据从一个函数中传出来。",
+ "示例",
+ "function plusThree(num) {
return num + 3;
}
var answer = plusThree(5); // 8
",
+ "plusThree
带有一个num
的参数并且返回(returns)一个等于num + 3
的值。",
"
",
- "Create a function timesFive
that accepts one argument, multiplies it by 5
, and returns the new value. See the last line in the editor for an example of how you can test your timesFive
function."
+ "创建一个函数timesFive
接收一个参数, 把它乘以5
之后返回,关于如何测试timesFive 函数,可以参考编辑器中最后一行的示例。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2728,20 +2727,20 @@
],
"tests": [
{
- "text": "timesFive
should be a function",
- "testString": "assert(typeof timesFive === 'function', 'timesFive
should be a function');"
+ "text": "timesFive
应是一个函数",
+ "testString": "assert(typeof timesFive === 'function', 'timesFive
应是一个函数');"
},
{
- "text": "timesFive(5)
should return 25
",
- "testString": "assert(timesFive(5) === 25, 'timesFive(5)
should return 25
');"
+ "text": "timesFive(5)
应该返回25
",
+ "testString": "assert(timesFive(5) === 25, 'timesFive(5)
应该返回25
');"
},
{
- "text": "timesFive(2)
should return 10
",
- "testString": "assert(timesFive(2) === 10, 'timesFive(2)
should return 10
');"
+ "text": "timesFive(2)
应该返回10
",
+ "testString": "assert(timesFive(2) === 10, 'timesFive(2)
应该返回10
');"
},
{
- "text": "timesFive(0)
should return 0
",
- "testString": "assert(timesFive(0) === 0, 'timesFive(0)
should return 0
');"
+ "text": "timesFive(0)
应该返回0
",
+ "testString": "assert(timesFive(0) === 0, 'timesFive(0)
应该返回0
');"
}
],
"challengeType": 1,
@@ -2751,12 +2750,12 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"function minusSeven(num) {",
" return num - 7;",
"}",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"",
"",
@@ -2771,12 +2770,12 @@
"id": "598e8944f009e646fc236146",
"title": "Understanding Undefined Value returned from a Function",
"description": [
- "A function can include the return
statement but it does not have to. In the case that the function doesn't have a return
statement, when you call it, the function processes the inner code but the returned value is undefined
.",
- "Example",
+ "函数一般用return
语句来返回值,但这不是必须的。在函数没有return
语句的情况下,当你调用它时,该函数会执行内部代码,返回的值是undefined
。",
+ "示例",
"var sum = 0;
function addSum(num) {
sum = sum + num;
}
var returnedValue = addSum(3); // sum will be modified but returned value is undefined
",
- "addSum
is a function without a return
statement. The function will change the global sum
variable but the returned value of the function is undefined
",
+ "addSum
是一个没有return
语句的函数。该函数将更改全局变量sum
,函数的返回值为undefined
。",
"
",
- "Create a function addFive
without any arguments. This function adds 5 to the sum
variable, but its returned value is undefined
."
+ "创建一个没有任何参数的函数addFive
。此函数使sum
变量加 5,但其返回值是undefined
。"
],
"releasedOn": "August 11, 2017",
"solutions": [
@@ -2784,16 +2783,16 @@
],
"tests": [
{
- "text": "addFive
should be a function",
- "testString": "assert(typeof addFive === 'function', 'addFive
should be a function');"
+ "text": "addFive
应该是一个函数",
+ "testString": "assert(typeof addFive === 'function', 'addFive
应该是一个函数');"
},
{
- "text": "sum
should be equal to 8",
- "testString": "assert(sum === 8, 'sum
should be equal to 8');"
+ "text": "sum
应该等于 8",
+ "testString": "assert(sum === 8, 'sum
应该等于 8');"
},
{
- "text": "Returned value from addFive
should be undefined
",
- "testString": "assert(addFive() === undefined, 'Returned value from addFive
should be undefined
');"
+ "text": "addFive
的返回值应该是undefined
",
+ "testString": "assert(addFive() === undefined, 'addFive
的返回值应该是undefined
');"
},
{
"text": "Inside of your functions, add 5 to the sum
variable",
@@ -2807,17 +2806,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var sum = 0;",
"function addThree() {",
" sum = sum + 3;",
"}",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
"",
"",
- "// Only change code above this line",
+ "// 请把你的代码写在这条注释以上",
"var returnedValue = addFive();"
],
"head": [],
@@ -2834,12 +2833,12 @@
"id": "56533eb9ac21ba0edf2244c3",
"title": "Assignment with a Returned Value",
"description": [
- "If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.",
- "Assume we have pre-defined a function sum
which adds two numbers together, then: ",
+ "如果你还记得我们在这一节 Storing Values with the Assignment Operator,的讨论,赋值之前,先完成等号右边的操作。这意味着我们可把一个函数的返回值,赋值给一个变量。",
+ "假设我们预先定义的函数sum
其功能就是将两个数字相加,那么:",
"ourSum = sum(5, 12);
",
- "will call sum
function, which returns a value of 17
and assigns it to ourSum
variable.",
+ "将调用sum
函数,返回return
了一个数值17
,然后把它赋值给了ourSum
变量。",
"
",
- "Call the processArg
function with an argument of 7
and assign its return value to the variable processed
."
+ "调用processArg
函数并给参数一个值7
,然后把返回的值赋值给变量processed
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2847,12 +2846,12 @@
],
"tests": [
{
- "text": "processed
should have a value of 2
",
- "testString": "assert(processed === 2, 'processed
should have a value of 2
');"
+ "text": "processed
的值应该是2
",
+ "testString": "assert(processed === 2, 'processed
的值应该是2
');"
},
{
- "text": "You should assign processArg
to processed
",
- "testString": "assert(/processed\\s*=\\s*processArg\\(\\s*7\\s*\\)\\s*;/.test(code), 'You should assign processArg
to processed
');"
+ "text": "你应该把processArg
的返回值赋给processed
",
+ "testString": "assert(/processed\\s*=\\s*processArg\\(\\s*7\\s*\\)\\s*;/.test(code), '你应该把processArg
的返回值赋给processed
');"
}
],
"challengeType": 1,
@@ -2863,7 +2862,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var changed = 0;",
"",
"function change(num) {",
@@ -2872,14 +2871,14 @@
"",
"changed = change(10);",
"",
- "// Setup",
+ "// 初始化变量",
"var processed = 0;",
"",
"function processArg(num) {",
" return (num + 3) / 5;",
"}",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -2894,10 +2893,10 @@
"id": "56533eb9ac21ba0edf2244c6",
"title": "Stand in Line",
"description": [
- "In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue
and old items are taken off from the front of the queue
.",
- "Write a function nextInLine
which takes an array (arr
) and a number (item
) as arguments.",
- "Add the number to the end of the array, then remove the first element of the array.",
- "The nextInLine
function should then return the element that was removed."
+ "在计算机科学中队列(queue)是一个抽象的数据结构,队列中的条目都是有秩序的。新的条目会被加到队列
的末尾,旧的条目会从队列
的头部被移出。",
+ "写一个函数nextInLine
,用一个数组(arr
)和一个数字(item
)作为参数。",
+ "把数字添加到数组的结尾,然后移出数组的第一个元素。",
+ "最后nextInLine
函数应该返回被删除的元素。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -2905,24 +2904,24 @@
],
"tests": [
{
- "text": "nextInLine([], 5)
should return a number.",
- "testString": "assert.isNumber(nextInLine([],5), 'nextInLine([], 5)
should return a number.');"
+ "text": "nextInLine([], 5)
应该返回一个数字",
+ "testString": "assert.isNumber(nextInLine([],5), 'nextInLine([], 5)
应该返回一个数字');"
},
{
- "text": "nextInLine([], 1)
should return 1
",
- "testString": "assert(nextInLine([],1) === 1, 'nextInLine([], 1)
should return 1
');"
+ "text": "nextInLine([], 1)
应该返回1
",
+ "testString": "assert(nextInLine([],1) === 1, 'nextInLine([], 1)
应该返回1
');"
},
{
- "text": "nextInLine([2], 1)
should return 2
",
- "testString": "assert(nextInLine([2],1) === 2, 'nextInLine([2], 1)
should return 2
');"
+ "text": "nextInLine([2], 1)
应该返回2
",
+ "testString": "assert(nextInLine([2],1) === 2, 'nextInLine([2], 1)
应该返回2
');"
},
{
- "text": "nextInLine([5,6,7,8,9], 1)
should return 5
",
- "testString": "assert(nextInLine([5,6,7,8,9],1) === 5, 'nextInLine([5,6,7,8,9], 1)
should return 5
');"
+ "text": "nextInLine([5,6,7,8,9], 1)
应该返回5
",
+ "testString": "assert(nextInLine([5,6,7,8,9],1) === 5, 'nextInLine([5,6,7,8,9], 1)
应该返回5
');"
},
{
- "text": "After nextInLine(testArr, 10)
, testArr[4]
should be 10
",
- "testString": "nextInLine(testArr, 10); assert(testArr[4] === 10, 'After nextInLine(testArr, 10)
, testArr[4]
should be 10
');"
+ "text": "在nextInLine(testArr, 10)
执行后testArr[4]
应该是10
",
+ "testString": "nextInLine(testArr, 10); assert(testArr[4] === 10, '在nextInLine(testArr, 10)
执行后testArr[4]
应该是10
');"
}
],
"challengeType": 1,
@@ -2933,15 +2932,15 @@
"name": "index",
"contents": [
"function nextInLine(arr, item) {",
- " // Your code here",
+ " // 请把你的代码写在这里",
" ",
- " return item; // Change this line",
+ " return item; // 请修改这一行",
"}",
"",
- "// Test Setup",
+ "// 初始化测试数据",
"var testArr = [1,2,3,4,5];",
"",
- "// Display Code",
+ "// 控制台输出",
"console.log(\"Before: \" + JSON.stringify(testArr));",
"console.log(nextInLine(testArr, 6)); // Modify this line to test",
"console.log(\"After: \" + JSON.stringify(testArr));"
@@ -2980,22 +2979,22 @@
"id": "bd7123c9c441eddfaeb5bdef",
"title": "Understanding Boolean Values",
"description": [
- "Another data type is the Boolean. Booleans
may only be one of two values: true
or false
. They are basically little on-off switches, where true
is \"on\" and false
is \"off.\" These two states are mutually exclusive.",
- "Note
Boolean
values are never written with quotes. The strings
\"true\"
and \"false\"
are not Boolean
and have no special meaning in JavaScript.",
+ "另一种数据类型是布尔(Boolean)。布尔
值要么是true
要么是false
。它非常像电路开关,true
是“开”,false
是“关”。这两种状态是互斥的。",
+ "注意
Boolean
值绝不会写被引号包裹起来的形式。字符串
的\"true\"
和\"false\"
不是布尔值
,在 JavaScript 中也没有特殊含义。",
"
",
- "Modify the welcomeToBooleans
function so that it returns true
instead of false
when the run button is clicked."
- ],
+ "修改welcomeToBooleans
函数,让它返回true
而不是false
。"
+ ],
"solutions": [
- "function welcomeToBooleans() {\n return true; // Change this line\n}"
+ "function welcomeToBooleans() {\n return true; // 请修改这一行\n}"
],
"tests": [
{
- "text": "The welcomeToBooleans()
function should return a boolean (true/false) value.",
- "testString": "assert(typeof welcomeToBooleans() === 'boolean', 'The welcomeToBooleans()
function should return a boolean (true/false) value.');"
+ "text": "welcomeToBooleans()
函数应该返回一个布尔值 (true/false) ",
+ "testString": "assert(typeof welcomeToBooleans() === 'boolean', 'welcomeToBooleans()
函数应该返回一个布尔值 (true/false) ');"
},
{
- "text": "welcomeToBooleans()
should return true.",
- "testString": "assert(welcomeToBooleans() === true, 'welcomeToBooleans()
should return true.');"
+ "text": "welcomeToBooleans()
应该返回 true",
+ "testString": "assert(welcomeToBooleans() === true, 'welcomeToBooleans()
应该返回 true');"
}
],
"challengeType": 1,
@@ -3007,11 +3006,11 @@
"contents": [
"function welcomeToBooleans() {",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
- "return false; // Change this line",
+ "return false; // 请修改这一行",
"",
- "// Only change code above this line.",
+ "// 请把你的代码写在这条注释以上.",
"}"
],
"head": [],
@@ -3025,39 +3024,39 @@
"id": "cf1111c1c12feddfaeb3bdef",
"title": "Use Conditional Logic with If Statements",
"description": [
- "If
statements are used to make decisions in code. The keyword if
tells JavaScript to execute the code in the curly braces under certain conditions, defined in the parentheses. These conditions are known as Boolean
conditions and they may only be true
or false
.",
- "When the condition evaluates to true
, the program executes the statement inside the curly braces. When the Boolean condition evaluates to false
, the statement inside the curly braces will not execute.",
- "Pseudocode",
- "if (condition is true) {
statement is executed
}
",
- "Example",
- "function test (myCondition) {
if (myCondition) {
return \"It was true\";
}
return \"It was false\";
}
test(true); // returns \"It was true\"
test(false); // returns \"It was false\"
",
- "When test
is called with a value of true
, the if
statement evaluates myCondition
to see if it is true
or not. Since it is true
, the function returns \"It was true\"
. When we call test
with a value of false
, myCondition
is not true
and the statement in the curly braces is not executed and the function returns \"It was false\"
.",
+ "If
语句用于在代码中做条件判断。关键字if
告诉 JavaScript 在小括号中的条件为真的情况下去执行定义在大括号里面的代码。这种条件被称为Boolean
条件,因为他们只可能是true
(真)或false
(假)。",
+ "当条件的计算结果为true
,程序执行大括号内的语句。当布尔条件的计算结果为false
,大括号内的代码将不会执行。",
+ "伪代码",
+ "if(条件为真){
语句被执行
}
",
+ "示例",
+ "function test (myCondition) {
if (myCondition) {
return \"It was true\";
}
return \"It was false\";
}
test(true); // 返回 \"It was true\"
test(false); // 返回 \"It was false\"
",
+ "当test
被调用,并且传递进来的参数值为true
,if
语句会计算myCondition
的结果,看它是真还是假。如果条件为true
,函数会返回\"It was true\"
。当test
被调用,并且传递进来的参数值为false
,myCondition
不 为true
,并且不执行大括号后面的语句,函数返回\"It was false\"
。",
"
",
- "Create an if
statement inside the function to return \"Yes, that was true\"
if the parameter wasThatTrue
is true
and return \"No, that was false\"
otherwise."
+ "在函数内部创建一个if
语句,如果该参数wasThatTrue
值为true
,返回\"That was true\"
,否则,并返回\"That was false\"
。"
],
"solutions": [
"function trueOrFalse(wasThatTrue) {\n if (wasThatTrue) {\n return \"Yes, that was true\";\n }\n return \"No, that was false\";\n}"
],
"tests": [
{
- "text": "trueOrFalse
should be a function",
- "testString": "assert(typeof trueOrFalse === \"function\", 'trueOrFalse
should be a function');"
+ "text": "trueOrFalse
应该是一个函数",
+ "testString": "assert(typeof trueOrFalse === \"function\", 'trueOrFalse
应该是一个函数');"
},
{
- "text": "trueOrFalse(true)
should return a string",
- "testString": "assert(typeof trueOrFalse(true) === \"string\", 'trueOrFalse(true)
should return a string');"
+ "text": "trueOrFalse(true)
应该返回一个字符串",
+ "testString": "assert(typeof trueOrFalse(true) === \"string\", 'trueOrFalse(true)
应该返回一个字符串');"
},
{
- "text": "trueOrFalse(false)
should return a string",
- "testString": "assert(typeof trueOrFalse(false) === \"string\", 'trueOrFalse(false)
should return a string');"
+ "text": "trueOrFalse(false)
应该返回一个字符串",
+ "testString": "assert(typeof trueOrFalse(false) === \"string\", 'trueOrFalse(false)
应该返回一个字符串');"
},
{
- "text": "trueOrFalse(true)
should return \"Yes, that was true\"",
- "testString": "assert(trueOrFalse(true) === \"Yes, that was true\", 'trueOrFalse(true)
should return \"Yes, that was true\"');"
+ "text": "trueOrFalse(true)
应该返回 \"Yes, that was true\"",
+ "testString": "assert(trueOrFalse(true) === \"Yes, that was true\", 'trueOrFalse(true)
应该返回 \"Yes, that was true\"');"
},
{
- "text": "trueOrFalse(false)
should return \"No, that was false\"",
- "testString": "assert(trueOrFalse(false) === \"No, that was false\", 'trueOrFalse(false)
should return \"No, that was false\"');"
+ "text": "trueOrFalse(false)
应该返回 \"No, that was false\"",
+ "testString": "assert(trueOrFalse(false) === \"No, that was false\", 'trueOrFalse(false)
应该返回 \"No, that was false\"');"
}
],
"challengeType": 1,
@@ -3067,7 +3066,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"function ourTrueOrFalse(isItTrue) {",
" if (isItTrue) { ",
" return \"Yes, it's true\";",
@@ -3075,18 +3074,18 @@
" return \"No, it's false\";",
"}",
"",
- "// Setup",
+ "// 初始化变量",
"function trueOrFalse(wasThatTrue) {",
"",
- " // Only change code below this line.",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line.",
+ " // 请把你的代码写在这条注释以上.",
"",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"trueOrFalse(true);"
],
"head": [],
@@ -3098,14 +3097,14 @@
"id": "56533eb9ac21ba0edf2244d0",
"title": "Comparison with the Equality Operator",
"description": [
- "There are many Comparison Operators in JavaScript. All of these operators return a boolean true
or false
value.",
- "The most basic operator is the equality operator ==
. The equality operator compares two values and returns true
if they're equivalent or false
if they are not. Note that equality is different from assignment (=
), which assigns the value at the right of the operator to a variable in the left.",
- "function equalityTest(myVal) {
if (myVal == 10) {
return \"Equal\";
}
return \"Not Equal\";
}
",
- "If myVal
is equal to 10
, the equality operator returns true
, so the code in the curly braces will execute, and the function will return \"Equal\"
. Otherwise, the function will return \"Not Equal\"
.",
- "In order for JavaScript to compare two different data types
(for example, numbers
and strings
), it must convert one type to another. This is known as \"Type Coercion\". Once it does, however, it can compare terms as follows:",
- "1 == 1 // true
1 == 2 // false
1 == '1' // true
\"3\" == 3 // true
",
+ "在 JavaScript 中,有很多相互比较的操作。所有这些操作符都返回一个true
或false
值。",
+ "最基本的运算符是相等运算符:==
。相等运算符比较两个值,如果它们是同等,返回true
,如果它们不等,返回false
。值得注意的是相等运算符不同于赋值运算符(=
),赋值运算符是把等号右边的值赋给左边的变量。",
+ "function equalityTest(myVal) {
if (myVal == 10) {
return \"Equal\";
}
return \"Not Equal\";
}
",
+ "如果myVal
等于10
,相等运算符会返回true
,因此大括号里面的代码会被执行,函数将返回\"Equal\"
。否则,函数返回\"Not Equal\"
。",
+ "在 JavaScript 中,为了让两个不同的数据类型
(例如数字
和字符串
)的值可以作比较,它必须把一种类型转换为另一种类型。然而一旦这样做,它可以像下面这样来比较:",
+ " 1 == 1 // true
1 == 2 // false
1 == '1' // true
\"3\" == 3 // true
",
"
",
- "Add the equality operator
to the indicated line so that the function will return \"Equal\" when val
is equivalent to 12
"
+ "把相等运算符
添加到指定的行,这样当val
的值为12
的时候,函数会返回\"Equal\"。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3113,20 +3112,20 @@
],
"tests": [
{
- "text": "testEqual(10)
should return \"Not Equal\"",
- "testString": "assert(testEqual(10) === \"Not Equal\", 'testEqual(10)
should return \"Not Equal\"');"
+ "text": "testEqual(10)
应该返回 \"Not Equal\"",
+ "testString": "assert(testEqual(10) === \"Not Equal\", 'testEqual(10)
应该返回 \"Not Equal\"');"
},
{
- "text": "testEqual(12)
should return \"Equal\"",
- "testString": "assert(testEqual(12) === \"Equal\", 'testEqual(12)
should return \"Equal\"');"
+ "text": "testEqual(12)
应该返回 \"Equal\"",
+ "testString": "assert(testEqual(12) === \"Equal\", 'testEqual(12)
应该返回 \"Equal\"');"
},
{
- "text": "testEqual(\"12\")
should return \"Equal\"",
- "testString": "assert(testEqual(\"12\") === \"Equal\", 'testEqual(\"12\")
should return \"Equal\"');"
+ "text": "testEqual(\"12\")
应该返回 \"Equal\"",
+ "testString": "assert(testEqual(\"12\") === \"Equal\", 'testEqual(\"12\")
应该返回 \"Equal\"');"
},
{
- "text": "You should use the ==
operator",
- "testString": "assert(code.match(/==/g) && !code.match(/===/g), 'You should use the ==
operator');"
+ "text": "你应该使用==
运算符",
+ "testString": "assert(code.match(/==/g) && !code.match(/===/g), '你应该使用==
运算符');"
}
],
"challengeType": 1,
@@ -3136,15 +3135,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function testEqual(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Equal\";",
" }",
" return \"Not Equal\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testEqual(10);"
],
"head": [],
@@ -3156,13 +3155,12 @@
"id": "56533eb9ac21ba0edf2244d1",
"title": "Comparison with the Strict Equality Operator",
"description": [
- "Strict equality (===
) is the counterpart to the equality operator (==
). However, unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion.",
- "If the values being compared have different types, they are considered unequal, and the strict equality operator will return false.",
- "Examples",
+ "严格相等运算符(===
)是相对相等操作符(==
)的另一种比较操作符。与相等操作符不同的是,它会同时比较元素的值和数据类型
。",
+ "示例",
"3 === 3 // true
3 === '3' // false
",
- "In the second example, 3
is a Number
type and '3'
is a String
type.",
+ "3
是一个数字
类型的,而'3'
是一个字符串
类型的,所以 3 不全等于 '3'。",
"
",
- "Use the strict equality operator in the if
statement so the function will return \"Equal\" when val
is strictly equal to 7
"
+ "在if
语句值使用严格相等运算符,这样当val
严格等于7的时候,函数会返回\"Equal\"。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3170,20 +3168,20 @@
],
"tests": [
{
- "text": "testStrict(10)
should return \"Not Equal\"",
- "testString": "assert(testStrict(10) === \"Not Equal\", 'testStrict(10)
should return \"Not Equal\"');"
+ "text": "testStrict(10)
应该返回 \"Not Equal\"",
+ "testString": "assert(testStrict(10) === \"Not Equal\", 'testStrict(10)
应该返回 \"Not Equal\"');"
},
{
- "text": "testStrict(7)
should return \"Equal\"",
- "testString": "assert(testStrict(7) === \"Equal\", 'testStrict(7)
should return \"Equal\"');"
+ "text": "testStrict(7)
应该返回 \"Equal\"",
+ "testString": "assert(testStrict(7) === \"Equal\", 'testStrict(7)
应该返回 \"Equal\"');"
},
{
- "text": "testStrict(\"7\")
should return \"Not Equal\"",
- "testString": "assert(testStrict(\"7\") === \"Not Equal\", 'testStrict(\"7\")
should return \"Not Equal\"');"
+ "text": "testStrict(\"7\")
应该返回 \"Not Equal\"",
+ "testString": "assert(testStrict(\"7\") === \"Not Equal\", 'testStrict(\"7\")
应该返回 \"Not Equal\"');"
},
{
- "text": "You should use the ===
operator",
- "testString": "assert(code.match(/(val\\s*===\\s*\\d+)|(\\d+\\s*===\\s*val)/g).length > 0, 'You should use the ===
operator');"
+ "text": "你应该使用===
运算符",
+ "testString": "assert(code.match(/(val\\s*===\\s*\\d+)|(\\d+\\s*===\\s*val)/g).length > 0, '你应该使用===
运算符');"
}
],
"challengeType": 1,
@@ -3193,15 +3191,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function testStrict(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Equal\";",
" }",
" return \"Not Equal\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testStrict(10);"
],
"head": [],
@@ -3213,14 +3211,14 @@
"id": "599a789b454f2bbd91a3ff4d",
"title": "Practice comparing different values",
"description": [
- "In the last two challenges, we learned about the equality operator (==
) and the strict equality operator (===
). Let's do a quick review and practice using these operators some more.",
- "If the values being compared are not of the same type, the equality operator will perform a type conversion, and then evaluate the values. However, the strict equality operator will compare both the data type and value as-is, without converting one type to the other.",
- "Examples",
- "3 == '3' // returns true because JavaScript performs type conversion from string to number
3 === '3' // returns false because the types are different and type conversion is not performed
",
- "Note
In JavaScript, you can determine the type of a variable or a value with the typeof
operator, as follows:",
- "typeof 3 // returns 'number'
typeof '3' // returns 'string'
",
+ "在上两个挑战中,我们学习了相等运算符 (==
) 和严格相等运算符 (===
)。让我们快速回顾并实践一下。",
+ "如果要比较的值不是同一类型,则相等运算符将执行类型转换,然后计算值。严格相等运算符则直接比较数据类型和值,不会进行类型换。",
+ "示例",
+ "3 == '3' // 返回 true,因为 JavaScript 会执行类型转换把字符串 '3' 转化成数字
3 === '3' // 返回 false,因为类型不同,而这里不会进行类型转换
",
+ "提示
在JavaScript中,您可以使用typeof
运算符确定变量的类型或值,如下所示:",
+ "typeof 3 // 返回 'number'
typeof '3' // 返回 'string'
",
"
",
- "The compareEquality
function in the editor compares two values using the equality operator
. Modify the function so that it returns \"Equal\" only when the values are strictly equal."
+ "编辑器中的compareEquality
函数使用相等运算符比较两个值。修改函数,使其仅在值严格相等时返回 \"Equal\" 。"
],
"releasedOn": "August 21, 2017",
"solutions": [
@@ -3228,16 +3226,16 @@
],
"tests": [
{
- "text": "compareEquality(10, \"10\")
should return \"Not Equal\"",
- "testString": "assert(compareEquality(10, \"10\") === \"Not Equal\", 'compareEquality(10, \"10\")
should return \"Not Equal\"');"
+ "text": "compareEquality(10, \"10\")
应该返回 \"Not Equal\"",
+ "testString": "assert(compareEquality(10, \"10\") === \"Not Equal\", 'compareEquality(10, \"10\")
应该返回 \"Not Equal\"');"
},
{
- "text": "compareEquality(\"20\", 20)
should return \"Not Equal\"",
- "testString": "assert(compareEquality(\"20\", 20) === \"Not Equal\", 'compareEquality(\"20\", 20)
should return \"Not Equal\"');"
+ "text": "compareEquality(\"20\", 20)
应该返回 \"Not Equal\"",
+ "testString": "assert(compareEquality(\"20\", 20) === \"Not Equal\", 'compareEquality(\"20\", 20)
应该返回 \"Not Equal\"');"
},
{
- "text": "You should use the ===
operator",
- "testString": "assert(code.match(/===/g), 'You should use the ===
operator');"
+ "text": "你应该使用 ===
运算符",
+ "testString": "assert(code.match(/===/g), '你应该使用===
运算符');"
}
],
"challengeType": 1,
@@ -3247,15 +3245,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function compareEquality(a, b) {",
- " if (a == b) { // Change this line",
+ " if (a == b) { // 请修改这一行",
" return \"Equal\";",
" }",
" return \"Not Equal\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"compareEquality(10, \"10\");"
],
"head": [],
@@ -3267,11 +3265,11 @@
"id": "56533eb9ac21ba0edf2244d2",
"title": "Comparison with the Inequality Operator",
"description": [
- "The inequality operator (!=
) is the opposite of the equality operator. It means \"Not Equal\" and returns false
where equality would return true
and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing.",
- "Examples",
+ "不相等运算符(!=
)与相等运算符是相反的。这意味着不相等运算符中,如果“不为真”并且返回false
的地方,在相等运算符中会返回true
,反之亦然。与相等运算符类似,不相等运算符在比较的时候也会转换值的数据类型。",
+ "例如",
"1 != 2 // true
1 != \"1\" // false
1 != '1' // false
1 != true // false
0 != false // false
",
"
",
- "Add the inequality operator !=
in the if
statement so that the function will return \"Not Equal\" when val
is not equivalent to 99
"
+ "在if
语句中,添加不相等运算符!=
,这样函数在当val
不等于 99
的时候,会返回 \"Not Equal\"。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3279,28 +3277,28 @@
],
"tests": [
{
- "text": "testNotEqual(99)
should return \"Equal\"",
- "testString": "assert(testNotEqual(99) === \"Equal\", 'testNotEqual(99)
should return \"Equal\"');"
+ "text": "testNotEqual(99)
应该返回 \"Equal\"",
+ "testString": "assert(testNotEqual(99) === \"Equal\", 'testNotEqual(99)
应该返回 \"Equal\"');"
},
{
- "text": "testNotEqual(\"99\")
should return \"Equal\"",
- "testString": "assert(testNotEqual(\"99\") === \"Equal\", 'testNotEqual(\"99\")
should return \"Equal\"');"
+ "text": "testNotEqual(\"99\")
应该返回 \"Equal\"",
+ "testString": "assert(testNotEqual(\"99\") === \"Equal\", 'testNotEqual(\"99\")
应该返回 \"Equal\"');"
},
{
- "text": "testNotEqual(12)
should return \"Not Equal\"",
- "testString": "assert(testNotEqual(12) === \"Not Equal\", 'testNotEqual(12)
should return \"Not Equal\"');"
+ "text": "testNotEqual(12)
应该返回 \"Not Equal\"",
+ "testString": "assert(testNotEqual(12) === \"Not Equal\", 'testNotEqual(12)
应该返回 \"Not Equal\"');"
},
{
- "text": "testNotEqual(\"12\")
should return \"Not Equal\"",
- "testString": "assert(testNotEqual(\"12\") === \"Not Equal\", 'testNotEqual(\"12\")
should return \"Not Equal\"');"
+ "text": "testNotEqual(\"12\")
应该返回 \"Not Equal\"",
+ "testString": "assert(testNotEqual(\"12\") === \"Not Equal\", 'testNotEqual(\"12\")
应该返回 \"Not Equal\"');"
},
{
- "text": "testNotEqual(\"bob\")
should return \"Not Equal\"",
- "testString": "assert(testNotEqual(\"bob\") === \"Not Equal\", 'testNotEqual(\"bob\")
should return \"Not Equal\"');"
+ "text": "testNotEqual(\"bob\")
应该返回 \"Not Equal\"",
+ "testString": "assert(testNotEqual(\"bob\") === \"Not Equal\", 'testNotEqual(\"bob\")
应该返回 \"Not Equal\"');"
},
{
- "text": "You should use the !=
operator",
- "testString": "assert(code.match(/(?!!==)!=/), 'You should use the !=
operator');"
+ "text": "你应该使用!=
运算符",
+ "testString": "assert(code.match(/(?!!==)!=/), '你应该使用!=
运算符');"
}
],
"challengeType": 1,
@@ -3310,15 +3308,15 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function testNotEqual(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Not Equal\";",
" }",
" return \"Equal\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testNotEqual(10);"
],
"head": [],
@@ -3330,11 +3328,11 @@
"id": "56533eb9ac21ba0edf2244d3",
"title": "Comparison with the Strict Inequality Operator",
"description": [
- "The strict inequality operator (!==
) is the logical opposite of the strict equality operator. It means \"Strictly Not Equal\" and returns false
where strict equality would return true
and vice versa. Strict inequality will not convert data types.",
- "Examples",
+ "严格不相等运算符(!==
)与全等运算符是相反的。这意味着严格不相等并返回false
的地方,用严格相等运算符会返回true
,反之亦然。严格相等运算符不会转换值的数据类型。",
+ "示例",
"3 !== 3 // false
3 !== '3' // true
4 !== 3 // true
",
"
",
- "Add the strict inequality operator
to the if
statement so the function will return \"Not Equal\" when val
is not strictly equal to 17
"
+ "在if
语句中,添加严格不相等运算符!==
,这样如果val
与17
严格不相等的时候,函数会返回 \"Not Equal\"。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3345,24 +3343,24 @@
],
"tests": [
{
- "text": "testStrictNotEqual(17)
should return \"Equal\"",
- "testString": "assert(testStrictNotEqual(17) === \"Equal\", 'testStrictNotEqual(17)
should return \"Equal\"');"
+ "text": "testStrictNotEqual(17)
应该返回 \"Equal\"",
+ "testString": "assert(testStrictNotEqual(17) === \"Equal\", 'testStrictNotEqual(17)
应该返回 \"Equal\"');"
},
{
- "text": "testStrictNotEqual(\"17\")
should return \"Not Equal\"",
- "testString": "assert(testStrictNotEqual(\"17\") === \"Not Equal\", 'testStrictNotEqual(\"17\")
should return \"Not Equal\"');"
+ "text": "testStrictNotEqual(\"17\")
应该返回 \"Not Equal\"",
+ "testString": "assert(testStrictNotEqual(\"17\") === \"Not Equal\", 'testStrictNotEqual(\"17\")
应该返回 \"Not Equal\"');"
},
{
- "text": "testStrictNotEqual(12)
should return \"Not Equal\"",
- "testString": "assert(testStrictNotEqual(12) === \"Not Equal\", 'testStrictNotEqual(12)
should return \"Not Equal\"');"
+ "text": "testStrictNotEqual(12)
应该返回 \"Not Equal\"",
+ "testString": "assert(testStrictNotEqual(12) === \"Not Equal\", 'testStrictNotEqual(12)
应该返回 \"Not Equal\"');"
},
{
- "text": "testStrictNotEqual(\"bob\")
should return \"Not Equal\"",
- "testString": "assert(testStrictNotEqual(\"bob\") === \"Not Equal\", 'testStrictNotEqual(\"bob\")
should return \"Not Equal\"');"
+ "text": "testStrictNotEqual(\"bob\")
应该返回 \"Not Equal\"",
+ "testString": "assert(testStrictNotEqual(\"bob\") === \"Not Equal\", 'testStrictNotEqual(\"bob\")
应该返回 \"Not Equal\"');"
},
{
"text": "You should use the !==
operator",
- "testString": "assert(code.match(/(val\\s*!==\\s*\\d+)|(\\d+\\s*!==\\s*val)/g).length > 0, 'You should use the !==
operator');"
+ "testString": "assert(code.match(/(val\\s*!==\\s*\\d+)|(\\d+\\s*!==\\s*val)/g).length > 0, '你应该使用!==
运算符');"
}
],
"challengeType": 1,
@@ -3372,20 +3370,20 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function testStrictNotEqual(val) {",
- " // Only Change Code Below this Line",
+ " // 请把你的代码写在这条注释以下",
" ",
" if (val) {",
"",
- " // Only Change Code Above this Line",
+ " // 请把你的代码写在这条注释以上",
"",
" return \"Not Equal\";",
" }",
" return \"Equal\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testStrictNotEqual(10);"
],
"head": [],
@@ -3397,49 +3395,49 @@
"id": "56533eb9ac21ba0edf2244d4",
"title": "Comparison with the Greater Than Operator",
"description": [
- "The greater than operator (>
) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns true
. Otherwise, it returns false
.",
- "Like the equality operator, greater than operator will convert data types of values while comparing.",
- "Examples",
+ "使用大于运算符(>
)来比较两个数字。如果大于运算符左边的数字大于右边的数字,将会返回true
。否则,它返回false
。",
+ "与相等运算符一样,大于运算符在比较的时候,会转换值的数据类型。",
+ "例如",
" 5 > 3 // true
7 > '3' // true
2 > 3 // false
'1' > 9 // false
",
"
",
- "Add the greater than
operator to the indicated lines so that the return statements make sense."
+ "添加大于
运算符到指定的行,使得返回的语句是有意义的。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "function testGreaterThan(val) {\n if (val > 100) { // Change this line\n return \"Over 100\";\n }\n if (val > 10) { // Change this line\n return \"Over 10\";\n }\n return \"10 or Under\";\n}"
+ "function testGreaterThan(val) {\n if (val > 100) { // 请修改这一行\n return \"Over 100\";\n }\n if (val > 10) { // 请修改这一行\n return \"Over 10\";\n }\n return \"10 or Under\";\n}"
],
"tests": [
{
- "text": "testGreaterThan(0)
should return \"10 or Under\"",
- "testString": "assert(testGreaterThan(0) === \"10 or Under\", 'testGreaterThan(0)
should return \"10 or Under\"');"
+ "text": "testGreaterThan(0)
应该返回 \"10 or Under\"",
+ "testString": "assert(testGreaterThan(0) === \"10 or Under\", 'testGreaterThan(0)
应该返回 \"10 or Under\"');"
},
{
- "text": "testGreaterThan(10)
should return \"10 or Under\"",
- "testString": "assert(testGreaterThan(10) === \"10 or Under\", 'testGreaterThan(10)
should return \"10 or Under\"');"
+ "text": "testGreaterThan(10)
应该返回 \"10 or Under\"",
+ "testString": "assert(testGreaterThan(10) === \"10 or Under\", 'testGreaterThan(10)
应该返回 \"10 or Under\"');"
},
{
- "text": "testGreaterThan(11)
should return \"Over 10\"",
- "testString": "assert(testGreaterThan(11) === \"Over 10\", 'testGreaterThan(11)
should return \"Over 10\"');"
+ "text": "testGreaterThan(11)
应该返回 \"Over 10\"",
+ "testString": "assert(testGreaterThan(11) === \"Over 10\", 'testGreaterThan(11)
应该返回 \"Over 10\"');"
},
{
- "text": "testGreaterThan(99)
should return \"Over 10\"",
- "testString": "assert(testGreaterThan(99) === \"Over 10\", 'testGreaterThan(99)
should return \"Over 10\"');"
+ "text": "testGreaterThan(99)
应该返回 \"Over 10\"",
+ "testString": "assert(testGreaterThan(99) === \"Over 10\", 'testGreaterThan(99)
应该返回 \"Over 10\"');"
},
{
- "text": "testGreaterThan(100)
should return \"Over 10\"",
- "testString": "assert(testGreaterThan(100) === \"Over 10\", 'testGreaterThan(100)
should return \"Over 10\"');"
+ "text": "testGreaterThan(100)
应该返回 \"Over 10\"",
+ "testString": "assert(testGreaterThan(100) === \"Over 10\", 'testGreaterThan(100)
应该返回 \"Over 10\"');"
},
{
- "text": "testGreaterThan(101)
should return \"Over 100\"",
- "testString": "assert(testGreaterThan(101) === \"Over 100\", 'testGreaterThan(101)
should return \"Over 100\"');"
+ "text": "testGreaterThan(101)
应该返回 \"Over 100\"",
+ "testString": "assert(testGreaterThan(101) === \"Over 100\", 'testGreaterThan(101)
应该返回 \"Over 100\"');"
},
{
- "text": "testGreaterThan(150)
should return \"Over 100\"",
- "testString": "assert(testGreaterThan(150) === \"Over 100\", 'testGreaterThan(150)
should return \"Over 100\"');"
+ "text": "testGreaterThan(150)
应该返回 \"Over 100\"",
+ "testString": "assert(testGreaterThan(150) === \"Over 100\", 'testGreaterThan(150)
应该返回 \"Over 100\"');"
},
{
- "text": "You should use the >
operator at least twice",
- "testString": "assert(code.match(/val\\s*>\\s*('|\")*\\d+('|\")*/g).length > 1, 'You should use the >
operator at least twice');"
+ "text": "你应该使用>
运算符至少两次",
+ "testString": "assert(code.match(/val\\s*>\\s*('|\")*\\d+('|\")*/g).length > 1, '你应该使用>
运算符至少两次');"
}
],
"challengeType": 1,
@@ -3450,18 +3448,18 @@
"name": "index",
"contents": [
"function testGreaterThan(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Over 100\";",
" }",
" ",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Over 10\";",
" }",
"",
" return \"10 or Under\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testGreaterThan(10);"
],
"head": [],
@@ -3473,49 +3471,49 @@
"id": "56533eb9ac21ba0edf2244d5",
"title": "Comparison with the Greater Than Or Equal To Operator",
"description": [
- "The greater than or equal to
operator (>=
) compares the values of two numbers. If the number to the left is greater than or equal to the number to the right, it returns true
. Otherwise, it returns false
.",
- "Like the equality operator, greater than or equal to
operator will convert data types while comparing.",
- "Examples",
+ "使用大于等于
运算符(>=
)来比较两个数字的大小。如果大于等于运算符左边的数字比右边的数字大或者相等,它会返回true
。否则,它会返回false
。",
+ "与相等运算符相似,大于等于
运算符在比较的时候会转换值的数据类型。",
+ "例如",
" 6 >= 6 // true
7 >= '3' // true
2 >= 3 // false
'7' >= 9 // false
",
"
",
- "Add the greater than or equal to
operator to the indicated lines so that the return statements make sense."
+ "添加大于等于
运算符到指定行,使得函数的返回语句有意义。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "function testGreaterOrEqual(val) {\n if (val >= 20) { // Change this line\n return \"20 or Over\";\n }\n \n if (val >= 10) { // Change this line\n return \"10 or Over\";\n }\n\n return \"Less than 10\";\n}"
+ "function testGreaterOrEqual(val) {\n if (val >= 20) { // 请修改这一行\n return \"20 or Over\";\n }\n \n if (val >= 10) { // 请修改这一行\n return \"10 or Over\";\n }\n\n return \"Less than 10\";\n}"
],
"tests": [
{
- "text": "testGreaterOrEqual(0)
should return \"Less than 10\"",
- "testString": "assert(testGreaterOrEqual(0) === \"Less than 10\", 'testGreaterOrEqual(0)
should return \"Less than 10\"');"
+ "text": "testGreaterOrEqual(0)
应该返回 \"Less than 10\"",
+ "testString": "assert(testGreaterOrEqual(0) === \"Less than 10\", 'testGreaterOrEqual(0)
应该返回 \"Less than 10\"');"
},
{
- "text": "testGreaterOrEqual(9)
should return \"Less than 10\"",
- "testString": "assert(testGreaterOrEqual(9) === \"Less than 10\", 'testGreaterOrEqual(9)
should return \"Less than 10\"');"
+ "text": "testGreaterOrEqual(9)
应该返回 \"Less than 10\"",
+ "testString": "assert(testGreaterOrEqual(9) === \"Less than 10\", 'testGreaterOrEqual(9)
应该返回 \"Less than 10\"');"
},
{
- "text": "testGreaterOrEqual(10)
should return \"10 or Over\"",
- "testString": "assert(testGreaterOrEqual(10) === \"10 or Over\", 'testGreaterOrEqual(10)
should return \"10 or Over\"');"
+ "text": "testGreaterOrEqual(10)
应该返回 \"10 or Over\"",
+ "testString": "assert(testGreaterOrEqual(10) === \"10 or Over\", 'testGreaterOrEqual(10)
应该返回 \"10 or Over\"');"
},
{
- "text": "testGreaterOrEqual(11)
should return \"10 or Over\"",
- "testString": "assert(testGreaterOrEqual(11) === \"10 or Over\", 'testGreaterOrEqual(11)
should return \"10 or Over\"');"
+ "text": "testGreaterOrEqual(11)
应该返回 \"10 or Over\"",
+ "testString": "assert(testGreaterOrEqual(11) === \"10 or Over\", 'testGreaterOrEqual(11)
应该返回 \"10 or Over\"');"
},
{
- "text": "testGreaterOrEqual(19)
should return \"10 or Over\"",
- "testString": "assert(testGreaterOrEqual(19) === \"10 or Over\", 'testGreaterOrEqual(19)
should return \"10 or Over\"');"
+ "text": "testGreaterOrEqual(19)
应该返回 \"10 or Over\"",
+ "testString": "assert(testGreaterOrEqual(19) === \"10 or Over\", 'testGreaterOrEqual(19)
应该返回 \"10 or Over\"');"
},
{
- "text": "testGreaterOrEqual(100)
should return \"20 or Over\"",
- "testString": "assert(testGreaterOrEqual(100) === \"20 or Over\", 'testGreaterOrEqual(100)
should return \"20 or Over\"');"
+ "text": "testGreaterOrEqual(100)
应该返回 \"20 or Over\"",
+ "testString": "assert(testGreaterOrEqual(100) === \"20 or Over\", 'testGreaterOrEqual(100)
应该返回 \"20 or Over\"');"
},
{
- "text": "testGreaterOrEqual(21)
should return \"20 or Over\"",
- "testString": "assert(testGreaterOrEqual(21) === \"20 or Over\", 'testGreaterOrEqual(21)
should return \"20 or Over\"');"
+ "text": "testGreaterOrEqual(21)
应该返回 \"20 or Over\"",
+ "testString": "assert(testGreaterOrEqual(21) === \"20 or Over\", 'testGreaterOrEqual(21)
应该返回 \"20 or Over\"');"
},
{
- "text": "You should use the >=
operator at least twice",
- "testString": "assert(code.match(/val\\s*>=\\s*('|\")*\\d+('|\")*/g).length > 1, 'You should use the >=
operator at least twice');"
+ "text": "你应该使用>=
运算符至少两次",
+ "testString": "assert(code.match(/val\\s*>=\\s*('|\")*\\d+('|\")*/g).length > 1, '你应该使用>=
运算符至少两次');"
}
],
"challengeType": 1,
@@ -3526,18 +3524,18 @@
"name": "index",
"contents": [
"function testGreaterOrEqual(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"20 or Over\";",
" }",
" ",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"10 or Over\";",
" }",
"",
" return \"Less than 10\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testGreaterOrEqual(10);"
],
"head": [],
@@ -3549,44 +3547,44 @@
"id": "56533eb9ac21ba0edf2244d6",
"title": "Comparison with the Less Than Operator",
"description": [
- "The less than operator (<
) compares the values of two numbers. If the number to the left is less than the number to the right, it returns true
. Otherwise, it returns false
. Like the equality operator, less than operator converts data types while comparing.",
- "Examples",
- "2 < 5 // true
'3' < 7 // true
5 < 5 // false
3 < 2 // false
'8' < 4 // false
",
+ "使用小于运算符(<
)比较两个数字的大小。如果小于运算符左边的数字比右边的数字小,它会返回true
。否则,他会返回false
。与相等运算符类似,小于 运算符在做比较的时候会转换值的数据类型。",
+ "例如",
+ " 2 < 5 // true
'3' < 7 // true
5 < 5 // false
3 < 2 // false
'8' < 4 // false
",
"
",
- "Add the less than
operator to the indicated lines so that the return statements make sense."
+ "添加小于
运算符到指定行,使得函数的返回语句有意义。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "function testLessThan(val) {\n if (val < 25) { // Change this line\n return \"Under 25\";\n }\n \n if (val < 55) { // Change this line\n return \"Under 55\";\n }\n\n return \"55 or Over\";\n}"
+ "function testLessThan(val) {\n if (val < 25) { // 请修改这一行\n return \"Under 25\";\n }\n \n if (val < 55) { // 请修改这一行\n return \"Under 55\";\n }\n\n return \"55 or Over\";\n}"
],
"tests": [
{
- "text": "testLessThan(0)
should return \"Under 25\"",
- "testString": "assert(testLessThan(0) === \"Under 25\", 'testLessThan(0)
should return \"Under 25\"');"
+ "text": "testLessThan(0)
应该返回 \"Under 25\"",
+ "testString": "assert(testLessThan(0) === \"Under 25\", 'testLessThan(0)
应该返回 \"Under 25\"');"
},
{
- "text": "testLessThan(24)
should return \"Under 25\"",
- "testString": "assert(testLessThan(24) === \"Under 25\", 'testLessThan(24)
should return \"Under 25\"');"
+ "text": "testLessThan(24)
应该返回 \"Under 25\"",
+ "testString": "assert(testLessThan(24) === \"Under 25\", 'testLessThan(24)
应该返回 \"Under 25\"');"
},
{
- "text": "testLessThan(25)
should return \"Under 55\"",
- "testString": "assert(testLessThan(25) === \"Under 55\", 'testLessThan(25)
should return \"Under 55\"');"
+ "text": "testLessThan(25)
应该返回 \"Under 55\"",
+ "testString": "assert(testLessThan(25) === \"Under 55\", 'testLessThan(25)
应该返回 \"Under 55\"');"
},
{
- "text": "testLessThan(54)
should return \"Under 55\"",
- "testString": "assert(testLessThan(54) === \"Under 55\", 'testLessThan(54)
should return \"Under 55\"');"
+ "text": "testLessThan(54)
应该返回 \"Under 55\"",
+ "testString": "assert(testLessThan(54) === \"Under 55\", 'testLessThan(54)
应该返回 \"Under 55\"');"
},
{
- "text": "testLessThan(55)
should return \"55 or Over\"",
- "testString": "assert(testLessThan(55) === \"55 or Over\", 'testLessThan(55)
should return \"55 or Over\"');"
+ "text": "testLessThan(55)
应该返回 \"55 or Over\"",
+ "testString": "assert(testLessThan(55) === \"55 or Over\", 'testLessThan(55)
应该返回 \"55 or Over\"');"
},
{
- "text": "testLessThan(99)
should return \"55 or Over\"",
- "testString": "assert(testLessThan(99) === \"55 or Over\", 'testLessThan(99)
should return \"55 or Over\"');"
+ "text": "testLessThan(99)
应该返回 \"55 or Over\"",
+ "testString": "assert(testLessThan(99) === \"55 or Over\", 'testLessThan(99)
应该返回 \"55 or Over\"');"
},
{
- "text": "You should use the <
operator at least twice",
- "testString": "assert(code.match(/val\\s*<\\s*('|\")*\\d+('|\")*/g).length > 1, 'You should use the <
operator at least twice');"
+ "text": "你应该使用<
运算符至少两次",
+ "testString": "assert(code.match(/val\\s*<\\s*('|\")*\\d+('|\")*/g).length > 1, '你应该使用<
运算符至少两次');"
}
],
"challengeType": 1,
@@ -3597,18 +3595,18 @@
"name": "index",
"contents": [
"function testLessThan(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Under 25\";",
" }",
" ",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Under 55\";",
" }",
"",
" return \"55 or Over\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testLessThan(10);"
],
"head": [],
@@ -3620,48 +3618,48 @@
"id": "56533eb9ac21ba0edf2244d7",
"title": "Comparison with the Less Than Or Equal To Operator",
"description": [
- "The less than or equal to
operator (<=
) compares the values of two numbers. If the number to the left is less than or equal to the number to the right, it returns true
. If the number on the left is greater than the number on the right, it returns false
. Like the equality operator, less than or equal to
converts data types.",
- "Examples",
- "4 <= 5 // true
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
",
+ "使用小于等于
运算符(<=
)比较两个数字的大小。如果在小于等于运算符,左边的数字小于或者等于右边的数字,它会返回true
。如果在小于等于运算符,左边的数字大于或者等于右边的数字,它会返回false
。与相等运算符类型,小于等于
运算符会转换数据类型。",
+ "例如",
+ " 4 <= 5 // true
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
",
"
",
- "Add the less than or equal to
operator to the indicated lines so that the return statements make sense."
+ "添加小于等于
运算符到指定行,使得函数的返回语句有意义。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "function testLessOrEqual(val) {\n if (val <= 12) { // Change this line\n return \"Smaller Than or Equal to 12\";\n }\n \n if (val <= 24) { // Change this line\n return \"Smaller Than or Equal to 24\";\n }\n\n return \"More Than 24\";\n}"
+ "function testLessOrEqual(val) {\n if (val <= 12) { // 请修改这一行\n return \"Smaller Than or Equal to 12\";\n }\n \n if (val <= 24) { // 请修改这一行\n return \"Smaller Than or Equal to 24\";\n }\n\n return \"More Than 24\";\n}"
],
"tests": [
{
- "text": "testLessOrEqual(0)
should return \"Smaller Than or Equal to 12\"",
- "testString": "assert(testLessOrEqual(0) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(0)
should return \"Smaller Than or Equal to 12\"');"
+ "text": "testLessOrEqual(0)
应该返回 \"Smaller Than or Equal to 12\"",
+ "testString": "assert(testLessOrEqual(0) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(0)
应该返回 \"Smaller Than or Equal to 12\"');"
},
{
- "text": "testLessOrEqual(11)
should return \"Smaller Than or Equal to 12\"",
- "testString": "assert(testLessOrEqual(11) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(11)
should return \"Smaller Than or Equal to 12\"');"
+ "text": "testLessOrEqual(11)
应该返回 \"Smaller Than or Equal to 12\"",
+ "testString": "assert(testLessOrEqual(11) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(11)
应该返回 \"Smaller Than or Equal to 12\"');"
},
{
- "text": "testLessOrEqual(12)
should return \"Smaller Than or Equal to 12\"",
- "testString": "assert(testLessOrEqual(12) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(12)
should return \"Smaller Than or Equal to 12\"');"
+ "text": "testLessOrEqual(12)
应该返回 \"Smaller Than or Equal to 12\"",
+ "testString": "assert(testLessOrEqual(12) === \"Smaller Than or Equal to 12\", 'testLessOrEqual(12)
应该返回 \"Smaller Than or Equal to 12\"');"
},
{
- "text": "testLessOrEqual(23)
should return \"Smaller Than or Equal to 24\"",
- "testString": "assert(testLessOrEqual(23) === \"Smaller Than or Equal to 24\", 'testLessOrEqual(23)
should return \"Smaller Than or Equal to 24\"');"
+ "text": "testLessOrEqual(23)
应该返回 \"Smaller Than or Equal to 24\"",
+ "testString": "assert(testLessOrEqual(23) === \"Smaller Than or Equal to 24\", 'testLessOrEqual(23)
应该返回 \"Smaller Than or Equal to 24\"');"
},
{
- "text": "testLessOrEqual(24)
should return \"Smaller Than or Equal to 24\"",
- "testString": "assert(testLessOrEqual(24) === \"Smaller Than or Equal to 24\", 'testLessOrEqual(24)
should return \"Smaller Than or Equal to 24\"');"
+ "text": "testLessOrEqual(24)
应该返回 \"Smaller Than or Equal to 24\"",
+ "testString": "assert(testLessOrEqual(24) === \"Smaller Than or Equal to 24\", 'testLessOrEqual(24)
应该返回 \"Smaller Than or Equal to 24\"');"
},
{
- "text": "testLessOrEqual(25)
should return \"More Than 24\"",
- "testString": "assert(testLessOrEqual(25) === \"More Than 24\", 'testLessOrEqual(25)
should return \"More Than 24\"');"
+ "text": "testLessOrEqual(25)
应该返回 \"More Than 24\"",
+ "testString": "assert(testLessOrEqual(25) === \"More Than 24\", 'testLessOrEqual(25)
应该返回 \"More Than 24\"');"
},
{
- "text": "testLessOrEqual(55)
should return \"More Than 24\"",
- "testString": "assert(testLessOrEqual(55) === \"More Than 24\", 'testLessOrEqual(55)
should return \"More Than 24\"');"
+ "text": "testLessOrEqual(55)
应该返回 \"More Than 24\"",
+ "testString": "assert(testLessOrEqual(55) === \"More Than 24\", 'testLessOrEqual(55)
应该返回 \"More Than 24\"');"
},
{
- "text": "You should use the <=
operator at least twice",
- "testString": "assert(code.match(/val\\s*<=\\s*('|\")*\\d+('|\")*/g).length > 1, 'You should use the <=
operator at least twice');"
+ "text": "你应该使用<=
运算符至少两",
+ "testString": "assert(code.match(/val\\s*<=\\s*('|\")*\\d+('|\")*/g).length > 1, '你应该使用<=
运算符至少两');"
}
],
"challengeType": 1,
@@ -3672,18 +3670,18 @@
"name": "index",
"contents": [
"function testLessOrEqual(val) {",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Smaller Than or Equal to 12\";",
" }",
" ",
- " if (val) { // Change this line",
+ " if (val) { // 请修改这一行",
" return \"Smaller Than or Equal to 24\";",
" }",
"",
" return \"More Than 24\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testLessOrEqual(10);",
""
],
@@ -3696,13 +3694,13 @@
"id": "56533eb9ac21ba0edf2244d8",
"title": "Comparisons with the Logical And Operator",
"description": [
- "Sometimes you will need to test more than one thing at a time. The logical and operator (&&
) returns true
if and only if the operands to the left and right of it are true.",
- "The same effect could be achieved by nesting an if statement inside another if:",
- "if (num > 5) {
if (num < 10) {
return \"Yes\";
}
}
return \"No\";
",
- "will only return \"Yes\" if num
is greater than 5
and less than 10
. The same logic can be written as:",
- "if (num > 5 && num < 10) {
return \"Yes\";
}
return \"No\";
",
+ "有时你需要在一次判断中做多个操作。当且仅当运算符的左边和右边都是true
,逻辑与 运算符(&&
)才会返回true
。",
+ "同样的效果可以通过 if 语句的嵌套来实现:",
+ "if (num > 5) {
if (num < 10) {
return \"Yes\";
}
}
return \"No\";
",
+ "只有当num
的值在 6 和 9 之间(包括 6 和 9)才会返回 \"Yes\"。相同的逻辑可被写为:",
+ "if (num > 5 && num < 10) {
return \"Yes\";
}
return \"No\";
",
"
",
- "Combine the two if statements into one statement which will return \"Yes\"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, will return \"No\"
."
+ "结合两个 if 语句为一个语句,如果val
小于或等于50
并且大于或等于25
,返回\"Yes\"
。否则,将返回\"No\"
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3710,44 +3708,44 @@
],
"tests": [
{
- "text": "You should use the &&
operator once",
- "testString": "assert(code.match(/&&/g).length === 1, 'You should use the &&
operator once');"
+ "text": "你应该使用&&
运算符一次",
+ "testString": "assert(code.match(/&&/g).length === 1, '你应该使用&&
运算符一次');"
},
{
- "text": "You should only have one if
statement",
- "testString": "assert(code.match(/if/g).length === 1, 'You should only have one if
statement');"
+ "text": "你应该只有一个if
表达式",
+ "testString": "assert(code.match(/if/g).length === 1, '你应该只有一个if
表达式');"
},
{
- "text": "testLogicalAnd(0)
should return \"No\"",
- "testString": "assert(testLogicalAnd(0) === \"No\", 'testLogicalAnd(0)
should return \"No\"');"
+ "text": "testLogicalAnd(0)
应该返回 \"No\"",
+ "testString": "assert(testLogicalAnd(0) === \"No\", 'testLogicalAnd(0)
应该返回 \"No\"');"
},
{
- "text": "testLogicalAnd(24)
should return \"No\"",
- "testString": "assert(testLogicalAnd(24) === \"No\", 'testLogicalAnd(24)
should return \"No\"');"
+ "text": "testLogicalAnd(24)
应该返回 \"No\"",
+ "testString": "assert(testLogicalAnd(24) === \"No\", 'testLogicalAnd(24)
应该返回 \"No\"');"
},
{
- "text": "testLogicalAnd(25)
should return \"Yes\"",
- "testString": "assert(testLogicalAnd(25) === \"Yes\", 'testLogicalAnd(25)
should return \"Yes\"');"
+ "text": "testLogicalAnd(25)
应该返回 \"Yes\"",
+ "testString": "assert(testLogicalAnd(25) === \"Yes\", 'testLogicalAnd(25)
应该返回 \"Yes\"');"
},
{
- "text": "testLogicalAnd(30)
should return \"Yes\"",
- "testString": "assert(testLogicalAnd(30) === \"Yes\", 'testLogicalAnd(30)
should return \"Yes\"');"
+ "text": "testLogicalAnd(30)
应该返回 \"Yes\"",
+ "testString": "assert(testLogicalAnd(30) === \"Yes\", 'testLogicalAnd(30)
应该返回 \"Yes\"');"
},
{
- "text": "testLogicalAnd(50)
should return \"Yes\"",
- "testString": "assert(testLogicalAnd(50) === \"Yes\", 'testLogicalAnd(50)
should return \"Yes\"');"
+ "text": "testLogicalAnd(50)
应该返回 \"Yes\"",
+ "testString": "assert(testLogicalAnd(50) === \"Yes\", 'testLogicalAnd(50)
应该返回 \"Yes\"');"
},
{
- "text": "testLogicalAnd(51)
should return \"No\"",
- "testString": "assert(testLogicalAnd(51) === \"No\", 'testLogicalAnd(51)
should return \"No\"');"
+ "text": "testLogicalAnd(51)
应该返回 \"No\"",
+ "testString": "assert(testLogicalAnd(51) === \"No\", 'testLogicalAnd(51)
应该返回 \"No\"');"
},
{
- "text": "testLogicalAnd(75)
should return \"No\"",
- "testString": "assert(testLogicalAnd(75) === \"No\", 'testLogicalAnd(75)
should return \"No\"');"
+ "text": "testLogicalAnd(75)
应该返回 \"No\"",
+ "testString": "assert(testLogicalAnd(75) === \"No\", 'testLogicalAnd(75)
应该返回 \"No\"');"
},
{
- "text": "testLogicalAnd(80)
should return \"No\"",
- "testString": "assert(testLogicalAnd(80) === \"No\", 'testLogicalAnd(80)
should return \"No\"');"
+ "text": "testLogicalAnd(80)
应该返回 \"No\"",
+ "testString": "assert(testLogicalAnd(80) === \"No\", 'testLogicalAnd(80)
应该返回 \"No\"');"
}
],
"challengeType": 1,
@@ -3758,7 +3756,7 @@
"name": "index",
"contents": [
"function testLogicalAnd(val) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
"",
" if (val) {",
" if (val) {",
@@ -3766,11 +3764,11 @@
" }",
" }",
"",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return \"No\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testLogicalAnd(10);"
],
"head": [],
@@ -3782,14 +3780,14 @@
"id": "56533eb9ac21ba0edf2244d9",
"title": "Comparisons with the Logical Or Operator",
"description": [
- "The logical or operator (||
) returns true
if either of the operands is true
. Otherwise, it returns false
.",
- "The logical or operator is composed of two pipe symbols (|
). This can typically be found between your Backspace and Enter keys.",
- "The pattern below should look familiar from prior waypoints:",
+ "如果任何一个操作数是true
,逻辑或 运算符 (||
) 返回true
。反之,返回false
。",
+ "logical or逻辑或运算符由两个管道符号(|)组成。这个按键通常可以在 Backspace 和 Enter 键之间。",
+ "下面这样的语句你应该很熟悉:",
"if (num > 10) {
return \"No\";
}
if (num < 5) {
return \"No\";
}
return \"Yes\";
",
- "will return \"Yes\" only if num
is between 5
and 10
(5 and 10 included). The same logic can be written as:",
- "if (num > 10 || num < 5) {
return \"No\";
}
return \"Yes\";
",
+ "只有当num
大于等于 5 或小于等于 10 时,函数返回\"Yes\"。相同的逻辑可以简写成:",
+ "if (num > 10 || num < 5) {
return \"No\";
}
return \"Yes\";
",
"
",
- "Combine the two if
statements into one statement which returns \"Outside\"
if val
is not between 10
and 20
, inclusive. Otherwise, return \"Inside\"
."
+ "结合两个 if 语句为一个语句,如果val
不在 10 和 20 之间(包括 10 和 20),返回\"Outside\"
。反之,返回\"Inside\"
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3797,44 +3795,44 @@
],
"tests": [
{
- "text": "You should use the ||
operator once",
- "testString": "assert(code.match(/\\|\\|/g).length === 1, 'You should use the ||
operator once');"
+ "text": "你应该使用一次||
操作符",
+ "testString": "assert(code.match(/\\|\\|/g).length === 1, '你应该使用一次||
操作符');"
},
{
"text": "You should only have one if
statement",
- "testString": "assert(code.match(/if/g).length === 1, 'You should only have one if
statement');"
+ "testString": "assert(code.match(/if/g).length === 1, '你应该只有一个if
表达式');"
},
{
- "text": "testLogicalOr(0)
should return \"Outside\"",
- "testString": "assert(testLogicalOr(0) === \"Outside\", 'testLogicalOr(0)
should return \"Outside\"');"
+ "text": "testLogicalOr(0)
应该返回 \"Outside\"",
+ "testString": "assert(testLogicalOr(0) === \"Outside\", 'testLogicalOr(0)
应该返回 \"Outside\"');"
},
{
- "text": "testLogicalOr(9)
should return \"Outside\"",
- "testString": "assert(testLogicalOr(9) === \"Outside\", 'testLogicalOr(9)
should return \"Outside\"');"
+ "text": "testLogicalOr(9)
应该返回 \"Outside\"",
+ "testString": "assert(testLogicalOr(9) === \"Outside\", 'testLogicalOr(9)
应该返回 \"Outside\"');"
},
{
- "text": "testLogicalOr(10)
should return \"Inside\"",
- "testString": "assert(testLogicalOr(10) === \"Inside\", 'testLogicalOr(10)
should return \"Inside\"');"
+ "text": "testLogicalOr(10)
应该返回 \"Inside\"",
+ "testString": "assert(testLogicalOr(10) === \"Inside\", 'testLogicalOr(10)
应该返回 \"Inside\"');"
},
{
- "text": "testLogicalOr(15)
should return \"Inside\"",
- "testString": "assert(testLogicalOr(15) === \"Inside\", 'testLogicalOr(15)
should return \"Inside\"');"
+ "text": "testLogicalOr(15)
应该返回 \"Inside\"",
+ "testString": "assert(testLogicalOr(15) === \"Inside\", 'testLogicalOr(15)
应该返回 \"Inside\"');"
},
{
- "text": "testLogicalOr(19)
should return \"Inside\"",
- "testString": "assert(testLogicalOr(19) === \"Inside\", 'testLogicalOr(19)
should return \"Inside\"');"
+ "text": "testLogicalOr(19)
应该返回 \"Inside\"",
+ "testString": "assert(testLogicalOr(19) === \"Inside\", 'testLogicalOr(19)
应该返回 \"Inside\"');"
},
{
- "text": "testLogicalOr(20)
should return \"Inside\"",
- "testString": "assert(testLogicalOr(20) === \"Inside\", 'testLogicalOr(20)
should return \"Inside\"');"
+ "text": "testLogicalOr(20)
应该返回 \"Inside\"",
+ "testString": "assert(testLogicalOr(20) === \"Inside\", 'testLogicalOr(20)
应该返回 \"Inside\"');"
},
{
- "text": "testLogicalOr(21)
should return \"Outside\"",
- "testString": "assert(testLogicalOr(21) === \"Outside\", 'testLogicalOr(21)
should return \"Outside\"');"
+ "text": "testLogicalOr(21)
应该返回 \"Outside\"",
+ "testString": "assert(testLogicalOr(21) === \"Outside\", 'testLogicalOr(21)
应该返回 \"Outside\"');"
},
{
- "text": "testLogicalOr(25)
should return \"Outside\"",
- "testString": "assert(testLogicalOr(25) === \"Outside\", 'testLogicalOr(25)
should return \"Outside\"');"
+ "text": "testLogicalOr(25)
应该返回 \"Outside\"",
+ "testString": "assert(testLogicalOr(25) === \"Outside\", 'testLogicalOr(25)
应该返回 \"Outside\"');"
}
],
"challengeType": 1,
@@ -3845,7 +3843,7 @@
"name": "index",
"contents": [
"function testLogicalOr(val) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
"",
" if (val) {",
" return \"Outside\";",
@@ -3855,11 +3853,11 @@
" return \"Outside\";",
" }",
"",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return \"Inside\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testLogicalOr(15);"
],
"head": [],
@@ -3871,10 +3869,10 @@
"id": "56533eb9ac21ba0edf2244da",
"title": "Introducing Else Statements",
"description": [
- "When a condition for an if
statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an else
statement, an alternate block of code can be executed.",
+ "当if
语句的条件为真,大括号里的代码执行,那如果条件为假呢?正常情况下什么也不会发生。使用else语句,可以执行当条件为假时相应的代码。",
"if (num > 10) {
return \"Bigger than 10\";
} else {
return \"10 or Less\";
}
",
"
",
- "Combine the if
statements into a single if/else
statement."
+ "合并多个if
语句为一个if/else
语句。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3882,32 +3880,32 @@
],
"tests": [
{
- "text": "You should only have one if
statement in the editor",
- "testString": "assert(code.match(/if/g).length === 1, 'You should only have one if
statement in the editor');"
+ "text": "你应该只有一个if
表达式",
+ "testString": "assert(code.match(/if/g).length === 1, '你应该只有一个if
表达式');"
},
{
- "text": "You should use an else
statement",
- "testString": "assert(/else/g.test(code), 'You should use an else
statement');"
+ "text": "你应该使用一个else
表达式",
+ "testString": "assert(/else/g.test(code), '你应该使用一个else
表达式');"
},
{
- "text": "testElse(4)
should return \"5 or Smaller\"",
- "testString": "assert(testElse(4) === \"5 or Smaller\", 'testElse(4)
should return \"5 or Smaller\"');"
+ "text": "testElse(4)
应该返回 \"5 or Smaller\"",
+ "testString": "assert(testElse(4) === \"5 or Smaller\", 'testElse(4)
应该返回 \"5 or Smaller\"');"
},
{
- "text": "testElse(5)
should return \"5 or Smaller\"",
- "testString": "assert(testElse(5) === \"5 or Smaller\", 'testElse(5)
should return \"5 or Smaller\"');"
+ "text": "testElse(5)
应该返回 \"5 or Smaller\"",
+ "testString": "assert(testElse(5) === \"5 or Smaller\", 'testElse(5)
应该返回 \"5 or Smaller\"');"
},
{
- "text": "testElse(6)
should return \"Bigger than 5\"",
- "testString": "assert(testElse(6) === \"Bigger than 5\", 'testElse(6)
should return \"Bigger than 5\"');"
+ "text": "testElse(6)
应该返回 \"Bigger than 5\"",
+ "testString": "assert(testElse(6) === \"Bigger than 5\", 'testElse(6)
应该返回 \"Bigger than 5\"');"
},
{
- "text": "testElse(10)
should return \"Bigger than 5\"",
- "testString": "assert(testElse(10) === \"Bigger than 5\", 'testElse(10)
should return \"Bigger than 5\"');"
+ "text": "testElse(10)
应该返回 \"Bigger than 5\"",
+ "testString": "assert(testElse(10) === \"Bigger than 5\", 'testElse(10)
应该返回 \"Bigger than 5\"');"
},
{
- "text": "Do not change the code above or below the lines.",
- "testString": "assert(/var result = \"\";/.test(code) && /return result;/.test(code), 'Do not change the code above or below the lines.');"
+ "text": "不要修改上面和下面的代码",
+ "testString": "assert(/var result = \"\";/.test(code) && /return result;/.test(code), '不要修改上面和下面的代码');"
}
],
"challengeType": 1,
@@ -3919,7 +3917,7 @@
"contents": [
"function testElse(val) {",
" var result = \"\";",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" if (val > 5) {",
" result = \"Bigger than 5\";",
@@ -3929,11 +3927,11 @@
" result = \"5 or Smaller\";",
" }",
" ",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return result;",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testElse(4);",
""
],
@@ -3946,10 +3944,10 @@
"id": "56533eb9ac21ba0edf2244db",
"title": "Introducing Else If Statements",
"description": [
- "If you have multiple conditions that need to be addressed, you can chain if
statements together with else if
statements.",
- "if (num > 15) {
return \"Bigger than 15\";
} else if (num < 5) {
return \"Smaller than 5\";
} else {
return \"Between 5 and 15\";
}
",
+ "如果你有多个条件语句,你可以通过else if
语句把if
语句链起来。",
+ "if (num > 15) {
return \"Bigger than 15\";
} else if (num < 5) {
return \"Smaller than 5\";
} else {
return \"Between 5 and 15\";
}
",
"
",
- "Convert the logic to use else if
statements."
+ "使用else if
实现同样的效果。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -3957,32 +3955,32 @@
],
"tests": [
{
- "text": "You should have at least two else
statements",
- "testString": "assert(code.match(/else/g).length > 1, 'You should have at least two else
statements');"
+ "text": "你应该至少有两个else
表达式",
+ "testString": "assert(code.match(/else/g).length > 1, '你应该至少有两个else
表达式');"
},
{
- "text": "You should have at least two if
statements",
- "testString": "assert(code.match(/if/g).length > 1, 'You should have at least two if
statements');"
+ "text": "你应该至少有两个if
表达式",
+ "testString": "assert(code.match(/if/g).length > 1, '你应该至少有两个if
表达式');"
},
{
- "text": "testElseIf(0)
should return \"Smaller than 5\"",
- "testString": "assert(testElseIf(0) === \"Smaller than 5\", 'testElseIf(0)
should return \"Smaller than 5\"');"
+ "text": "testElseIf(0)
应该返回 \"Smaller than 5\"",
+ "testString": "assert(testElseIf(0) === \"Smaller than 5\", 'testElseIf(0)
应该返回 \"Smaller than 5\"');"
},
{
- "text": "testElseIf(5)
should return \"Between 5 and 10\"",
- "testString": "assert(testElseIf(5) === \"Between 5 and 10\", 'testElseIf(5)
should return \"Between 5 and 10\"');"
+ "text": "testElseIf(5)
应该返回 \"Between 5 and 10\"",
+ "testString": "assert(testElseIf(5) === \"Between 5 and 10\", 'testElseIf(5)
应该返回 \"Between 5 and 10\"');"
},
{
- "text": "testElseIf(7)
should return \"Between 5 and 10\"",
- "testString": "assert(testElseIf(7) === \"Between 5 and 10\", 'testElseIf(7)
should return \"Between 5 and 10\"');"
+ "text": "testElseIf(7)
应该返回 \"Between 5 and 10\"",
+ "testString": "assert(testElseIf(7) === \"Between 5 and 10\", 'testElseIf(7)
应该返回 \"Between 5 and 10\"');"
},
{
- "text": "testElseIf(10)
should return \"Between 5 and 10\"",
- "testString": "assert(testElseIf(10) === \"Between 5 and 10\", 'testElseIf(10)
should return \"Between 5 and 10\"');"
+ "text": "testElseIf(10)
应该返回 \"Between 5 and 10\"",
+ "testString": "assert(testElseIf(10) === \"Between 5 and 10\", 'testElseIf(10)
应该返回 \"Between 5 and 10\"');"
},
{
- "text": "testElseIf(12)
should return \"Greater than 10\"",
- "testString": "assert(testElseIf(12) === \"Greater than 10\", 'testElseIf(12)
should return \"Greater than 10\"');"
+ "text": "testElseIf(12)
应该返回 \"Greater than 10\"",
+ "testString": "assert(testElseIf(12) === \"Greater than 10\", 'testElseIf(12)
应该返回 \"Greater than 10\"');"
}
],
"challengeType": 1,
@@ -4004,7 +4002,7 @@
" return \"Between 5 and 10\";",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testElseIf(7);",
""
],
@@ -4017,33 +4015,33 @@
"id": "5690307fddb111c6084545d7",
"title": "Logical Order in If Else Statements",
"description": [
- "Order is important in if
, else if
statements.",
- "The function is executed from top to bottom so you will want to be careful of what statement comes first.",
- "Take these two functions as an example.",
- "Here's the first:",
- "function foo(x) {
if (x < 1) {
return \"Less than one\";
} else if (x < 2) {
return \"Less than two\";
} else {
return \"Greater than or equal to two\";
}
}
",
- "And the second just switches the order of the statements:",
- "function bar(x) {
if (x < 2) {
return \"Less than two\";
} else if (x < 1) {
return \"Less than one\";
} else {
return \"Greater than or equal to two\";
}
}
",
- "While these two functions look nearly identical if we pass a number to both we get different outputs.",
+ "if
、else if
语句中代码的执行顺序是很重要的。",
+ "在条件判断语句中,代码的执行顺序是从上到下,所以你需要考虑清楚先执行哪一句,后执行哪一句。",
+ "这有两个例子。",
+ "第一个例子:",
+ "function foo(x) {
if (x < 1) {
return \"Less than one\";
} else if (x < 2) {
return \"Less than two\";
} else {
return \"Greater than or equal to two\";
}
}
",
+ "第二个例子更改了代码的执行顺序:",
+ "function bar(x) {
if (x < 2) {
return \"Less than two\";
} else if (x < 1) {
return \"Less than one\";
} else {
return \"Greater than or equal to two\";
}
}
",
+ "这两个函数看起来几乎一模一样,我们传一个值进去看看它们有什么区别。",
"foo(0) // \"Less than one\"
bar(0) // \"Less than two\"
",
"
",
- "Change the order of logic in the function so that it will return the correct statements in all cases."
+ "更改函数的逻辑顺序以便通过所有的测试用例。"
],
"solutions": [
"function orderMyLogic(val) {\n if(val < 5) {\n return \"Less than 5\"; \n } else if (val < 10) {\n return \"Less than 10\";\n } else {\n return \"Greater than or equal to 10\";\n }\n}"
],
"tests": [
{
- "text": "orderMyLogic(4)
should return \"Less than 5\"",
- "testString": "assert(orderMyLogic(4) === \"Less than 5\", 'orderMyLogic(4)
should return \"Less than 5\"');"
+ "text": "orderMyLogic(4)
应该返回 \"Less than 5\"",
+ "testString": "assert(orderMyLogic(4) === \"Less than 5\", 'orderMyLogic(4)
应该返回 \"Less than 5\"');"
},
{
- "text": "orderMyLogic(6)
should return \"Less than 10\"",
- "testString": "assert(orderMyLogic(6) === \"Less than 10\", 'orderMyLogic(6)
should return \"Less than 10\"');"
+ "text": "orderMyLogic(6)
应该返回 \"Less than 10\"",
+ "testString": "assert(orderMyLogic(6) === \"Less than 10\", 'orderMyLogic(6)
应该返回 \"Less than 10\"');"
},
{
- "text": "orderMyLogic(11)
should return \"Greater than or equal to 10\"",
- "testString": "assert(orderMyLogic(11) === \"Greater than or equal to 10\", 'orderMyLogic(11)
should return \"Greater than or equal to 10\"');"
+ "text": "orderMyLogic(11)
应该返回 \"Greater than or equal to 10\"",
+ "testString": "assert(orderMyLogic(11) === \"Greater than or equal to 10\", 'orderMyLogic(11)
应该返回 \"Greater than or equal to 10\"');"
}
],
"challengeType": 1,
@@ -4063,7 +4061,7 @@
" }",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"orderMyLogic(7);"
],
"head": [],
@@ -4075,11 +4073,11 @@
"id": "56533eb9ac21ba0edf2244dc",
"title": "Chaining If Else Statements",
"description": [
- "if/else
statements can be chained together for complex logic. Here is pseudocode of multiple chained if
/ else if
statements:",
- "if (condition1) {
statement1
} else if (condition2) {
statement2
} else if (condition3) {
statement3
. . .
} else {
statementN
}
",
+ "if/else
语句串联在一起可以实现复杂的逻辑,这是多个if/else if
语句串联在一起的伪代码:",
+ "if (condition1) {
statement1
} else if (condition2) {
statement2
} else if (condition3) {
statement3
. . .
} else {
statementN
}
",
"
",
- "Write chained if
/else if
statements to fulfill the following conditions:",
- "num < 5
- return \"Tiny\"
num < 10
- return \"Small\"
num < 15
- return \"Medium\"
num < 20
- return \"Large\"
num >= 20
- return \"Huge\""
+ "把if
/else if
语句串联起来实现下面的逻辑:",
+ "num < 5
- return \"Tiny\"
num < 10
- return \"Small\"
num < 15
- return \"Medium\"
num < 20
- return \"Large\"
num >= 20
- return \"Huge\""
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4087,56 +4085,56 @@
],
"tests": [
{
- "text": "You should have at least four else
statements",
- "testString": "assert(code.match(/else/g).length > 3, 'You should have at least four else
statements');"
+ "text": "你应该有至少 4 个else
表达式",
+ "testString": "assert(code.match(/else/g).length > 3, '你应该有至少 4 个else
表达式');"
},
{
- "text": "You should have at least four if
statements",
- "testString": "assert(code.match(/if/g).length > 3, 'You should have at least four if
statements');"
+ "text": "你应该有至少 4 个if
表达式",
+ "testString": "assert(code.match(/if/g).length > 3, '你应该有至少 4 个if
表达式');"
},
{
- "text": "You should have at least one return
statement",
- "testString": "assert(code.match(/return/g).length >= 1, 'You should have at least one return
statement');"
+ "text": "你应该有至少 1 个return
表达式",
+ "testString": "assert(code.match(/return/g).length >= 1, '你应该有至少 1 个return
表达式');"
},
{
- "text": "testSize(0)
should return \"Tiny\"",
- "testString": "assert(testSize(0) === \"Tiny\", 'testSize(0)
should return \"Tiny\"');"
+ "text": "testSize(0)
应该返回 \"Tiny\"",
+ "testString": "assert(testSize(0) === \"Tiny\", 'testSize(0)
应该返回 \"Tiny\"');"
},
{
- "text": "testSize(4)
should return \"Tiny\"",
- "testString": "assert(testSize(4) === \"Tiny\", 'testSize(4)
should return \"Tiny\"');"
+ "text": "testSize(4)
应该返回 \"Tiny\"",
+ "testString": "assert(testSize(4) === \"Tiny\", 'testSize(4)
应该返回 \"Tiny\"');"
},
{
- "text": "testSize(5)
should return \"Small\"",
- "testString": "assert(testSize(5) === \"Small\", 'testSize(5)
should return \"Small\"');"
+ "text": "testSize(5)
应该返回 \"Small\"",
+ "testString": "assert(testSize(5) === \"Small\", 'testSize(5)
应该返回 \"Small\"');"
},
{
- "text": "testSize(8)
should return \"Small\"",
- "testString": "assert(testSize(8) === \"Small\", 'testSize(8)
should return \"Small\"');"
+ "text": "testSize(8)
应该返回 \"Small\"",
+ "testString": "assert(testSize(8) === \"Small\", 'testSize(8)
应该返回 \"Small\"');"
},
{
- "text": "testSize(10)
should return \"Medium\"",
- "testString": "assert(testSize(10) === \"Medium\", 'testSize(10)
should return \"Medium\"');"
+ "text": "testSize(10)
应该返回 \"Medium\"",
+ "testString": "assert(testSize(10) === \"Medium\", 'testSize(10)
应该返回 \"Medium\"');"
},
{
- "text": "testSize(14)
should return \"Medium\"",
- "testString": "assert(testSize(14) === \"Medium\", 'testSize(14)
should return \"Medium\"');"
+ "text": "testSize(14)
应该返回 \"Medium\"",
+ "testString": "assert(testSize(14) === \"Medium\", 'testSize(14)
应该返回 \"Medium\"');"
},
{
- "text": "testSize(15)
should return \"Large\"",
- "testString": "assert(testSize(15) === \"Large\", 'testSize(15)
should return \"Large\"');"
+ "text": "testSize(15)
应该返回 \"Large\"",
+ "testString": "assert(testSize(15) === \"Large\", 'testSize(15)
应该返回 \"Large\"');"
},
{
- "text": "testSize(17)
should return \"Large\"",
- "testString": "assert(testSize(17) === \"Large\", 'testSize(17)
should return \"Large\"');"
+ "text": "testSize(17)
应该返回 \"Large\"",
+ "testString": "assert(testSize(17) === \"Large\", 'testSize(17)
应该返回 \"Large\"');"
},
{
- "text": "testSize(20)
should return \"Huge\"",
- "testString": "assert(testSize(20) === \"Huge\", 'testSize(20)
should return \"Huge\"');"
+ "text": "testSize(20)
应该返回 \"Huge\"",
+ "testString": "assert(testSize(20) === \"Huge\", 'testSize(20)
应该返回 \"Huge\"');"
},
{
- "text": "testSize(25)
should return \"Huge\"",
- "testString": "assert(testSize(25) === \"Huge\", 'testSize(25)
should return \"Huge\"');"
+ "text": "testSize(25)
应该返回 \"Huge\"",
+ "testString": "assert(testSize(25) === \"Huge\", 'testSize(25)
应该返回 \"Huge\"');"
}
],
"challengeType": 1,
@@ -4147,14 +4145,14 @@
"name": "index",
"contents": [
"function testSize(num) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" return \"Change Me\";",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"testSize(7);"
],
"head": [],
@@ -4166,10 +4164,10 @@
"id": "5664820f61c48e80c9fa476c",
"title": "Golf Code",
"description": [
- "In the game of golf each hole has a par
meaning the average number of strokes
a golfer is expected to make in order to sink the ball in a hole to complete the play. Depending on how far above or below par
your strokes
are, there is a different nickname.",
- "Your function will be passed par
and strokes
arguments. Return the correct string according to this table which lists the strokes in order of priority; top (highest) to bottom (lowest):",
+ "在高尔夫golf游戏中,每个洞都有自己的标准杆数par
,代表着距离。根据你把球打进洞所挥杆的次数strokes
,可以计算出你的高尔夫水平。",
+ "函数将会传送 2 个参数,分别是标准杆数par
和挥杆次数strokes
,根据下面的表格返回正确的水平段位。",
"Strokes | Return |
---|
1 | \"Hole-in-one!\" |
<= par - 2 | \"Eagle\" |
par - 1 | \"Birdie\" |
par | \"Par\" |
par + 1 | \"Bogey\" |
par + 2 | \"Double Bogey\" |
>= par + 3 | \"Go Home!\" |
",
- "par
and strokes
will always be numeric and positive. We have added an array of all the names for your convenience."
+ "par
和strokes
必须是数字而且是正数。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4177,48 +4175,48 @@
],
"tests": [
{
- "text": "golfScore(4, 1)
should return \"Hole-in-one!\"",
- "testString": "assert(golfScore(4, 1) === \"Hole-in-one!\", 'golfScore(4, 1)
should return \"Hole-in-one!\"');"
+ "text": "golfScore(4, 1)
应该返回 \"Hole-in-one!\"",
+ "testString": "assert(golfScore(4, 1) === \"Hole-in-one!\", 'golfScore(4, 1)
应该返回 \"Hole-in-one!\"');"
},
{
- "text": "golfScore(4, 2)
should return \"Eagle\"",
- "testString": "assert(golfScore(4, 2) === \"Eagle\", 'golfScore(4, 2)
should return \"Eagle\"');"
+ "text": "golfScore(4, 2)
应该返回 \"Eagle\"",
+ "testString": "assert(golfScore(4, 2) === \"Eagle\", 'golfScore(4, 2)
应该返回 \"Eagle\"');"
},
{
- "text": "golfScore(5, 2)
should return \"Eagle\"",
- "testString": "assert(golfScore(5, 2) === \"Eagle\", 'golfScore(5, 2)
should return \"Eagle\"');"
+ "text": "golfScore(5, 2)
应该返回 \"Eagle\"",
+ "testString": "assert(golfScore(5, 2) === \"Eagle\", 'golfScore(5, 2)
应该返回 \"Eagle\"');"
},
{
- "text": "golfScore(4, 3)
should return \"Birdie\"",
- "testString": "assert(golfScore(4, 3) === \"Birdie\", 'golfScore(4, 3)
should return \"Birdie\"');"
+ "text": "golfScore(4, 3)
应该返回 \"Birdie\"",
+ "testString": "assert(golfScore(4, 3) === \"Birdie\", 'golfScore(4, 3)
应该返回 \"Birdie\"');"
},
{
- "text": "golfScore(4, 4)
should return \"Par\"",
- "testString": "assert(golfScore(4, 4) === \"Par\", 'golfScore(4, 4)
should return \"Par\"');"
+ "text": "golfScore(4, 4)
应该返回 \"Par\"",
+ "testString": "assert(golfScore(4, 4) === \"Par\", 'golfScore(4, 4)
应该返回 \"Par\"');"
},
{
- "text": "golfScore(1, 1)
should return \"Hole-in-one!\"",
- "testString": "assert(golfScore(1, 1) === \"Hole-in-one!\", 'golfScore(1, 1)
should return \"Hole-in-one!\"');"
+ "text": "golfScore(1, 1)
应该返回 \"Hole-in-one!\"",
+ "testString": "assert(golfScore(1, 1) === \"Hole-in-one!\", 'golfScore(1, 1)
应该返回 \"Hole-in-one!\"');"
},
{
- "text": "golfScore(5, 5)
should return \"Par\"",
- "testString": "assert(golfScore(5, 5) === \"Par\", 'golfScore(5, 5)
should return \"Par\"');"
+ "text": "golfScore(5, 5)
应该返回 \"Par\"",
+ "testString": "assert(golfScore(5, 5) === \"Par\", 'golfScore(5, 5)
应该返回 \"Par\"');"
},
{
- "text": "golfScore(4, 5)
should return \"Bogey\"",
- "testString": "assert(golfScore(4, 5) === \"Bogey\", 'golfScore(4, 5)
should return \"Bogey\"');"
+ "text": "golfScore(4, 5)
应该返回 \"Bogey\"",
+ "testString": "assert(golfScore(4, 5) === \"Bogey\", 'golfScore(4, 5)
应该返回 \"Bogey\"');"
},
{
- "text": "golfScore(4, 6)
should return \"Double Bogey\"",
- "testString": "assert(golfScore(4, 6) === \"Double Bogey\", 'golfScore(4, 6)
should return \"Double Bogey\"');"
+ "text": "golfScore(4, 6)
应该返回 \"Double Bogey\"",
+ "testString": "assert(golfScore(4, 6) === \"Double Bogey\", 'golfScore(4, 6)
应该返回 \"Double Bogey\"');"
},
{
- "text": "golfScore(4, 7)
should return \"Go Home!\"",
- "testString": "assert(golfScore(4, 7) === \"Go Home!\", 'golfScore(4, 7)
should return \"Go Home!\"');"
+ "text": "golfScore(4, 7)
应该返回 \"Go Home!\"",
+ "testString": "assert(golfScore(4, 7) === \"Go Home!\", 'golfScore(4, 7)
应该返回 \"Go Home!\"');"
},
{
- "text": "golfScore(5, 9)
should return \"Go Home!\"",
- "testString": "assert(golfScore(5, 9) === \"Go Home!\", 'golfScore(5, 9)
should return \"Go Home!\"');"
+ "text": "golfScore(5, 9)
应该返回 \"Go Home!\"",
+ "testString": "assert(golfScore(5, 9) === \"Go Home!\", 'golfScore(5, 9)
应该返回 \"Go Home!\"');"
}
],
"challengeType": 1,
@@ -4230,11 +4228,11 @@
"contents": [
"var names = [\"Hole-in-one!\", \"Eagle\", \"Birdie\", \"Par\", \"Bogey\", \"Double Bogey\", \"Go Home!\"];",
"function golfScore(par, strokes) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" return \"Change Me\";",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
"}",
"",
"// Change these values to test",
@@ -4249,12 +4247,12 @@
"id": "56533eb9ac21ba0edf2244dd",
"title": "Selecting from Many Options with Switch Statements",
"description": [
- "If you have many options to choose from, use a switch
statement. A switch
statement tests a value and can have many case
statements which define various possible values. Statements are executed from the first matched case
value until a break
is encountered.",
- "Here is a pseudocode example:",
- "switch(num) {
case value1:
statement1;
break;
case value2:
statement2;
break;
...
case valueN:
statementN;
break;
}
",
- "case
values are tested with strict equality (===
). The break
tells JavaScript to stop executing statements. If the break
is omitted, the next statement will be executed.",
+ "如果你有非常多的选项需要选择,可以使用 switch 语句。根据不同的参数值会匹配上不同的 case 分支,语句会从第一个匹配的 case 分支开始执行,直到碰到 break 就结束。",
+ "这是一个伪代码案例:",
+ "switch(num) {
case value1:
statement1;
break;
case value2:
statement2;
break;
...
case valueN:
statementN;
break;
}
",
+ "测试case
值使用严格相等运算符进行比较,break 关键字告诉 JavaScript 停止执行语句。如果没有 break 关键字,下一个语句会继续执行。",
"
",
- "Write a switch statement which tests val
and sets answer
for the following conditions:
1
- \"alpha\"
2
- \"beta\"
3
- \"gamma\"
4
- \"delta\""
+ "写一个测试val
的 switch 语句,并且根据下面的条件来设置不同的answer
:
1
- \"alpha\"
2
- \"beta\"
3
- \"gamma\"
4
- \"delta\""
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4262,28 +4260,28 @@
],
"tests": [
{
- "text": "caseInSwitch(1)
should have a value of \"alpha\"",
- "testString": "assert(caseInSwitch(1) === \"alpha\", 'caseInSwitch(1)
should have a value of \"alpha\"');"
+ "text": "caseInSwitch(1)
应该有一个值为 \"alpha\"",
+ "testString": "assert(caseInSwitch(1) === \"alpha\", 'caseInSwitch(1)
应该有一个值为 \"alpha\"');"
},
{
- "text": "caseInSwitch(2)
should have a value of \"beta\"",
- "testString": "assert(caseInSwitch(2) === \"beta\", 'caseInSwitch(2)
should have a value of \"beta\"');"
+ "text": "caseInSwitch(2)
应该有一个值为 \"beta\"",
+ "testString": "assert(caseInSwitch(2) === \"beta\", 'caseInSwitch(2)
应该有一个值为 \"beta\"');"
},
{
- "text": "caseInSwitch(3)
should have a value of \"gamma\"",
- "testString": "assert(caseInSwitch(3) === \"gamma\", 'caseInSwitch(3)
should have a value of \"gamma\"');"
+ "text": "caseInSwitch(3)
应该有一个值为 \"gamma\"",
+ "testString": "assert(caseInSwitch(3) === \"gamma\", 'caseInSwitch(3)
应该有一个值为 \"gamma\"');"
},
{
- "text": "caseInSwitch(4)
should have a value of \"delta\"",
- "testString": "assert(caseInSwitch(4) === \"delta\", 'caseInSwitch(4)
should have a value of \"delta\"');"
+ "text": "caseInSwitch(4)
应该有一个值为 \"delta\"",
+ "testString": "assert(caseInSwitch(4) === \"delta\", 'caseInSwitch(4)
应该有一个值为 \"delta\"');"
},
{
- "text": "You should not use any if
or else
statements",
- "testString": "assert(!/else/g.test(code) || !/if/g.test(code), 'You should not use any if
or else
statements');"
+ "text": "不能使用任何if
或else
表达式",
+ "testString": "assert(!/else/g.test(code) || !/if/g.test(code), '不能使用任何if
或else
表达式');"
},
{
- "text": "You should have at least 3 break
statements",
- "testString": "assert(code.match(/break/g).length > 2, 'You should have at least 3 break
statements');"
+ "text": "你应该有至少 3 个break
表达式",
+ "testString": "assert(code.match(/break/g).length > 2, '你应该有至少 3 个break
表达式');"
}
],
"MDNlinks": [
@@ -4298,15 +4296,15 @@
"contents": [
"function caseInSwitch(val) {",
" var answer = \"\";",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line ",
+ " // 请把你的代码写在这条注释以上 ",
" return answer; ",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"caseInSwitch(1);",
""
],
@@ -4319,11 +4317,11 @@
"id": "56533eb9ac21ba0edf2244de",
"title": "Adding a Default Option in Switch Statements",
"description": [
- "In a switch
statement you may not be able to specify all possible values as case
statements. Instead, you can add the default
statement which will be executed if no matching case
statements are found. Think of it like the final else
statement in an if/else
chain.",
- "A default
statement should be the last case.",
+ "在switch
语句中你可能无法用 case 来指定所有情况,这时你可以添加 default 语句。当再也找不到 case 匹配的时候 default 语句会执行,非常类似于 if/else 组合中的 else 语句。",
+ "default
语句应该是最后一个 case。",
"switch (num) {
case value1:
statement1;
break;
case value2:
statement2;
break;
...
default:
defaultStatement;
break;
}
",
"
",
- "Write a switch statement to set answer
for the following conditions:
\"a\"
- \"apple\"
\"b\"
- \"bird\"
\"c\"
- \"cat\"
default
- \"stuff\""
+ "写一个根据下面的条件来设置answer
的switch语句:
\"a\"
- \"apple\"
\"b\"
- \"bird\"
\"c\"
- \"cat\"
default
- \"stuff\""
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4331,36 +4329,36 @@
],
"tests": [
{
- "text": "switchOfStuff(\"a\")
should have a value of \"apple\"",
- "testString": "assert(switchOfStuff(\"a\") === \"apple\", 'switchOfStuff(\"a\")
should have a value of \"apple\"');"
+ "text": "switchOfStuff(\"a\")
应该有一个值为 \"apple\"",
+ "testString": "assert(switchOfStuff(\"a\") === \"apple\", 'switchOfStuff(\"a\")
应该有一个值为 \"apple\"');"
},
{
- "text": "switchOfStuff(\"b\")
should have a value of \"bird\"",
- "testString": "assert(switchOfStuff(\"b\") === \"bird\", 'switchOfStuff(\"b\")
should have a value of \"bird\"');"
+ "text": "switchOfStuff(\"b\")
应该有一个值为 \"bird\"",
+ "testString": "assert(switchOfStuff(\"b\") === \"bird\", 'switchOfStuff(\"b\")
应该有一个值为 \"bird\"');"
},
{
- "text": "switchOfStuff(\"c\")
should have a value of \"cat\"",
- "testString": "assert(switchOfStuff(\"c\") === \"cat\", 'switchOfStuff(\"c\")
should have a value of \"cat\"');"
+ "text": "switchOfStuff(\"c\")
应该有一个值为 \"cat\"",
+ "testString": "assert(switchOfStuff(\"c\") === \"cat\", 'switchOfStuff(\"c\")
应该有一个值为 \"cat\"');"
},
{
- "text": "switchOfStuff(\"d\")
should have a value of \"stuff\"",
- "testString": "assert(switchOfStuff(\"d\") === \"stuff\", 'switchOfStuff(\"d\")
should have a value of \"stuff\"');"
+ "text": "switchOfStuff(\"d\")
应该有一个值为 \"stuff\"",
+ "testString": "assert(switchOfStuff(\"d\") === \"stuff\", 'switchOfStuff(\"d\")
应该有一个值为 \"stuff\"');"
},
{
- "text": "switchOfStuff(4)
should have a value of \"stuff\"",
- "testString": "assert(switchOfStuff(4) === \"stuff\", 'switchOfStuff(4)
should have a value of \"stuff\"');"
+ "text": "switchOfStuff(4)
应该有一个值为 \"stuff\"",
+ "testString": "assert(switchOfStuff(4) === \"stuff\", 'switchOfStuff(4)
应该有一个值为 \"stuff\"');"
},
{
- "text": "You should not use any if
or else
statements",
- "testString": "assert(!/else/g.test(code) || !/if/g.test(code), 'You should not use any if
or else
statements');"
+ "text": "不能使用任何if
或else
表达式",
+ "testString": "assert(!/else/g.test(code) || !/if/g.test(code), '不能使用任何if
或else
表达式');"
},
{
- "text": "You should use a default
statement",
- "testString": "assert(switchOfStuff(\"string-to-trigger-default-case\") === \"stuff\", 'You should use a default
statement');"
+ "text": "你应该有一个default
表达式",
+ "testString": "assert(switchOfStuff(\"string-to-trigger-default-case\") === \"stuff\", '你应该有一个default
表达式');"
},
{
- "text": "You should have at least 3 break
statements",
- "testString": "assert(code.match(/break/g).length > 2, 'You should have at least 3 break
statements');"
+ "text": "你应该有至少 3 个break
表达式",
+ "testString": "assert(code.match(/break/g).length > 2, '你应该有至少 3 个break
表达式');"
}
],
"challengeType": 1,
@@ -4373,15 +4371,15 @@
"contents": [
"function switchOfStuff(val) {",
" var answer = \"\";",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line ",
+ " // 请把你的代码写在这条注释以上 ",
" return answer; ",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"switchOfStuff(1);",
""
],
@@ -4399,7 +4397,7 @@
"Cases for 1, 2, and 3 will all produce the same result.",
"
",
"Write a switch statement to set answer
for the following ranges:
1-3
- \"Low\"
4-6
- \"Mid\"
7-9
- \"High\"",
- "Note
You will need to have a case
statement for each number in the range."
+ "提示
You will need to have a case
statement for each number in the range."
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4407,40 +4405,40 @@
],
"tests": [
{
- "text": "sequentialSizes(1)
should return \"Low\"",
- "testString": "assert(sequentialSizes(1) === \"Low\", 'sequentialSizes(1)
should return \"Low\"');"
+ "text": "sequentialSizes(1)
应该返回 \"Low\"",
+ "testString": "assert(sequentialSizes(1) === \"Low\", 'sequentialSizes(1)
应该返回 \"Low\"');"
},
{
- "text": "sequentialSizes(2)
should return \"Low\"",
- "testString": "assert(sequentialSizes(2) === \"Low\", 'sequentialSizes(2)
should return \"Low\"');"
+ "text": "sequentialSizes(2)
应该返回 \"Low\"",
+ "testString": "assert(sequentialSizes(2) === \"Low\", 'sequentialSizes(2)
应该返回 \"Low\"');"
},
{
- "text": "sequentialSizes(3)
should return \"Low\"",
- "testString": "assert(sequentialSizes(3) === \"Low\", 'sequentialSizes(3)
should return \"Low\"');"
+ "text": "sequentialSizes(3)
应该返回 \"Low\"",
+ "testString": "assert(sequentialSizes(3) === \"Low\", 'sequentialSizes(3)
应该返回 \"Low\"');"
},
{
- "text": "sequentialSizes(4)
should return \"Mid\"",
- "testString": "assert(sequentialSizes(4) === \"Mid\", 'sequentialSizes(4)
should return \"Mid\"');"
+ "text": "sequentialSizes(4)
应该返回 \"Mid\"",
+ "testString": "assert(sequentialSizes(4) === \"Mid\", 'sequentialSizes(4)
应该返回 \"Mid\"');"
},
{
- "text": "sequentialSizes(5)
should return \"Mid\"",
- "testString": "assert(sequentialSizes(5) === \"Mid\", 'sequentialSizes(5)
should return \"Mid\"');"
+ "text": "sequentialSizes(5)
应该返回 \"Mid\"",
+ "testString": "assert(sequentialSizes(5) === \"Mid\", 'sequentialSizes(5)
应该返回 \"Mid\"');"
},
{
- "text": "sequentialSizes(6)
should return \"Mid\"",
- "testString": "assert(sequentialSizes(6) === \"Mid\", 'sequentialSizes(6)
should return \"Mid\"');"
+ "text": "sequentialSizes(6)
应该返回 \"Mid\"",
+ "testString": "assert(sequentialSizes(6) === \"Mid\", 'sequentialSizes(6)
应该返回 \"Mid\"');"
},
{
- "text": "sequentialSizes(7)
should return \"High\"",
- "testString": "assert(sequentialSizes(7) === \"High\", 'sequentialSizes(7)
should return \"High\"');"
+ "text": "sequentialSizes(7)
应该返回 \"High\"",
+ "testString": "assert(sequentialSizes(7) === \"High\", 'sequentialSizes(7)
应该返回 \"High\"');"
},
{
- "text": "sequentialSizes(8)
should return \"High\"",
- "testString": "assert(sequentialSizes(8) === \"High\", 'sequentialSizes(8)
should return \"High\"');"
+ "text": "sequentialSizes(8)
应该返回 \"High\"",
+ "testString": "assert(sequentialSizes(8) === \"High\", 'sequentialSizes(8)
应该返回 \"High\"');"
},
{
- "text": "sequentialSizes(9)
should return \"High\"",
- "testString": "assert(sequentialSizes(9) === \"High\", 'sequentialSizes(9)
should return \"High\"');"
+ "text": "sequentialSizes(9)
应该返回 \"High\"",
+ "testString": "assert(sequentialSizes(9) === \"High\", 'sequentialSizes(9)
应该返回 \"High\"');"
},
{
"text": "You should not use any if
or else
statements",
@@ -4460,15 +4458,15 @@
"contents": [
"function sequentialSizes(val) {",
" var answer = \"\";",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line ",
+ " // 请把你的代码写在这条注释以上 ",
" return answer; ",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"sequentialSizes(1);",
""
],
@@ -4481,12 +4479,12 @@
"id": "56533eb9ac21ba0edf2244e0",
"title": "Replacing If Else Chains with Switch",
"description": [
- "If you have many options to choose from, a switch
statement can be easier to write than many chained if
/else if
statements. The following:",
+ "如果你有多个选项需要选择,switch
语句写起来会比多个串联的if
/if else
语句容易些,譬如:",
"if (val === 1) {
answer = \"a\";
} else if (val === 2) {
answer = \"b\";
} else {
answer = \"c\";
}
",
- "can be replaced with:",
+ "可以被下面替代:",
"switch(val) {
case 1:
answer = \"a\";
break;
case 2:
answer = \"b\";
break;
default:
answer = \"c\";
}
",
"
",
- "Change the chained if
/else if
statements into a switch
statement."
+ "把串联的if
/if else
语句改成switch
语句。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4494,44 +4492,44 @@
],
"tests": [
{
- "text": "You should not use any else
statements anywhere in the editor",
- "testString": "assert(!/else/g.test(code), 'You should not use any else
statements anywhere in the editor');"
+ "text": "不要使用else
表达式",
+ "testString": "assert(!/else/g.test(code), '不要使用else
表达式');"
},
{
- "text": "You should not use any if
statements anywhere in the editor",
- "testString": "assert(!/if/g.test(code), 'You should not use any if
statements anywhere in the editor');"
+ "text": "不要使用if
表达式",
+ "testString": "assert(!/if/g.test(code), '不要使用if
表达式');"
},
{
- "text": "You should have at least four break
statements",
- "testString": "assert(code.match(/break/g).length >= 4, 'You should have at least four break
statements');"
+ "text": "你应该有至少 4 个break
表达式",
+ "testString": "assert(code.match(/break/g).length >= 4, '你应该有至少 4 个break
表达式');"
},
{
- "text": "chainToSwitch(\"bob\")
should be \"Marley\"",
- "testString": "assert(chainToSwitch(\"bob\") === \"Marley\", 'chainToSwitch(\"bob\")
should be \"Marley\"');"
+ "text": "chainToSwitch(\"bob\")
应该为 \"Marley\"');",
+ "testString": "assert(chainToSwitch(\"bob\") === \"Marley\", 'chainToSwitch(\"bob\")
应该为 \"Marley\"');');"
},
{
- "text": "chainToSwitch(42)
should be \"The Answer\"",
- "testString": "assert(chainToSwitch(42) === \"The Answer\", 'chainToSwitch(42)
should be \"The Answer\"');"
+ "text": "chainToSwitch(42)
应该为 \"The Answer\"",
+ "testString": "assert(chainToSwitch(42) === \"The Answer\", 'chainToSwitch(42)
应该为 \"The Answer\"');"
},
{
- "text": "chainToSwitch(1)
should be \"There is no #1\"",
- "testString": "assert(chainToSwitch(1) === \"There is no #1\", 'chainToSwitch(1)
should be \"There is no #1\"');"
+ "text": "chainToSwitch(1)
应该为 \"There is no #1\"",
+ "testString": "assert(chainToSwitch(1) === \"There is no #1\", 'chainToSwitch(1)
应该为 \"There is no #1\"');"
},
{
- "text": "chainToSwitch(99)
should be \"Missed me by this much!\"",
- "testString": "assert(chainToSwitch(99) === \"Missed me by this much!\", 'chainToSwitch(99)
should be \"Missed me by this much!\"');"
+ "text": "chainToSwitch(99)
应该为 \"Missed me by this much!\"",
+ "testString": "assert(chainToSwitch(99) === \"Missed me by this much!\", 'chainToSwitch(99)
应该为 \"Missed me by this much!\"');"
},
{
- "text": "chainToSwitch(7)
should be \"Ate Nine\"",
- "testString": "assert(chainToSwitch(7) === \"Ate Nine\", 'chainToSwitch(7)
should be \"Ate Nine\"');"
+ "text": "chainToSwitch(7)
应该为 \"Ate Nine\"",
+ "testString": "assert(chainToSwitch(7) === \"Ate Nine\", 'chainToSwitch(7)
应该为 \"Ate Nine\"');"
},
{
- "text": "chainToSwitch(\"John\")
should be \"\" (empty string)",
- "testString": "assert(chainToSwitch(\"John\") === \"\", 'chainToSwitch(\"John\")
should be \"\" (empty string)');"
+ "text": "chainToSwitch(\"John\")
应该为 \"\" (empty string)",
+ "testString": "assert(chainToSwitch(\"John\") === \"\", 'chainToSwitch(\"John\")
应该为 \"\" (empty string)');"
},
{
- "text": "chainToSwitch(156)
should be \"\" (empty string)",
- "testString": "assert(chainToSwitch(156) === \"\", 'chainToSwitch(156)
should be \"\" (empty string)');"
+ "text": "chainToSwitch(156)
应该为 \"\" (empty string)",
+ "testString": "assert(chainToSwitch(156) === \"\", 'chainToSwitch(156)
应该为 \"\" (empty string)');"
}
],
"challengeType": 1,
@@ -4543,7 +4541,7 @@
"contents": [
"function chainToSwitch(val) {",
" var answer = \"\";",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" if (val === \"bob\") {",
" answer = \"Marley\";",
@@ -4557,11 +4555,11 @@
" answer = \"Ate Nine\";",
" }",
" ",
- " // Only change code above this line ",
+ " // 请把你的代码写在这条注释以上 ",
" return answer; ",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"chainToSwitch(7);",
""
],
@@ -4574,13 +4572,13 @@
"id": "5679ceb97cbaa8c51670a16b",
"title": "Returning Boolean Values from Functions",
"description": [
- "You may recall from Comparison with the Equality Operator that all comparison operators return a boolean true
or false
value.",
- "Sometimes people use an if/else statement to do a comparison, like this:",
+ "你可能会回想起,所有的比较操作符返回的都是一个 boolean 值,要么是true
要么是false
。",
+ "有时人们通过 if/else 语句来做比较然后返回true
或false
。",
"function isEqual(a,b) {
if (a === b) {
return true;
} else {
return false;
}
}
",
- "But there's a better way to do this. Since ===
returns true
or false
, we can return the result of the comparison:",
+ "有一个更好的方法,因为===
总是返回true
或false
,所以我们可以直接返回比较的结果:",
"function isEqual(a,b) {
return a === b;
}
",
"
",
- "Fix the function isLess
to remove the if/else
statements."
+ "移除isLess
函数的if/else
语句但不影响函数的功能。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4588,16 +4586,16 @@
],
"tests": [
{
- "text": "isLess(10,15)
should return true
",
- "testString": "assert(isLess(10,15) === true, 'isLess(10,15)
should return true
');"
+ "text": "isLess(10,15)
应该返回 true
",
+ "testString": "assert(isLess(10,15) === true, 'isLess(10,15)
应该返回 true
');"
},
{
- "text": "isLess(15,10)
should return false
",
- "testString": "assert(isLess(15, 10) === false, 'isLess(15,10)
should return false
');"
+ "text": "isLess(15,10)
应该返回 false
",
+ "testString": "assert(isLess(15, 10) === false, 'isLess(15,10)
应该返回 false
');"
},
{
"text": "You should not use any if
or else
statements",
- "testString": "assert(!/if|else/g.test(code), 'You should not use any if
or else
statements');"
+ "testString": "assert(!/if|else/g.test(code), '不要使用if
或else
表达式');"
}
],
"challengeType": 1,
@@ -4608,7 +4606,7 @@
"name": "index",
"contents": [
"function isLess(a, b) {",
- " // Fix this code",
+ " // 请修改这部分代码",
" if (a < b) {",
" return true;",
" } else {",
@@ -4628,13 +4626,13 @@
"id": "56533eb9ac21ba0edf2244c4",
"title": "Return Early Pattern for Functions",
"description": [
- "When a return
statement is reached, the execution of the current function stops and control returns to the calling location.",
- "Example",
+ "当代码执行到 return 语句时,函数返回一个结果就结束运行了,return 后面的语句不会执行。",
+ "示例",
"function myFun() {
console.log(\"Hello\");
return \"World\";
console.log(\"byebye\")
}
myFun();
",
- "The above outputs \"Hello\" to the console, returns \"World\", but \"byebye\"
is never output, because the function exits at the return
statement.",
+ "上面的代码输出\"Hello\"到控制台、返回 \"World\",但没有输出\"byebye\"
,因为函数遇到 return 语句就退出了。",
"
",
- "Modify the function abTest
so that if a
or b
are less than 0
the function will immediately exit with a value of undefined
.",
- "Hint
Remember that undefined
is a keyword, not a string."
+ "修改函数abTest
当a
或b
小于0时,函数立即返回一个undefined
并退出。",
+ "提示
记住undefined
,是一个关键字,而不是一个字符串。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4642,28 +4640,28 @@
],
"tests": [
{
- "text": "abTest(2,2)
should return a number",
- "testString": "assert(typeof abTest(2,2) === 'number' , 'abTest(2,2)
should return a number');"
+ "text": "abTest(2,2)
应该返回 a number",
+ "testString": "assert(typeof abTest(2,2) === 'number' , 'abTest(2,2)
应该返回 a number');"
},
{
- "text": "abTest(2,2)
should return 8
",
- "testString": "assert(abTest(2,2) === 8 , 'abTest(2,2)
should return 8
');"
+ "text": "abTest(2,2)
应该返回 8
",
+ "testString": "assert(abTest(2,2) === 8 , 'abTest(2,2)
应该返回 8
');"
},
{
- "text": "abTest(-2,2)
should return undefined
",
- "testString": "assert(abTest(-2,2) === undefined , 'abTest(-2,2)
should return undefined
');"
+ "text": "abTest(-2,2)
应该返回 undefined
",
+ "testString": "assert(abTest(-2,2) === undefined , 'abTest(-2,2)
应该返回 undefined
');"
},
{
- "text": "abTest(2,-2)
should return undefined
",
- "testString": "assert(abTest(2,-2) === undefined , 'abTest(2,-2)
should return undefined
');"
+ "text": "abTest(2,-2)
应该返回 undefined
",
+ "testString": "assert(abTest(2,-2) === undefined , 'abTest(2,-2)
应该返回 undefined
');"
},
{
- "text": "abTest(2,8)
should return 18
",
- "testString": "assert(abTest(2,8) === 18 , 'abTest(2,8)
should return 18
');"
+ "text": "abTest(2,8)
应该返回 18
",
+ "testString": "assert(abTest(2,8) === 18 , 'abTest(2,8)
应该返回 18
');"
},
{
- "text": "abTest(3,3)
should return 12
",
- "testString": "assert(abTest(3,3) === 12 , 'abTest(3,3)
should return 12
');"
+ "text": "abTest(3,3)
应该返回 12
",
+ "testString": "assert(abTest(3,3) === 12 , 'abTest(3,3)
应该返回 12
');"
}
],
"challengeType": 1,
@@ -4673,18 +4671,18 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function abTest(a, b) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" ",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
"",
" return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));",
"}",
"",
- "// Change values below to test your code",
+ "// 你可以修改这一行来测试你的代码",
"abTest(2,2);"
],
"head": [],
@@ -4696,12 +4694,12 @@
"id": "565bbe00e9cc8ac0725390f4",
"title": "Counting Cards",
"description": [
- "In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.",
- "Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.",
+ "在赌场 21 点游戏中,玩家可以通过计算牌桌上已经发放的卡牌的高低值来让自己在游戏中保持优势,这就叫 21 点算法。",
+ "根据下面的表格,每张卡牌都分配了一个值。如果卡牌的值大于 0,那么玩家应该追加赌注。反之,追加少许赌注甚至不追加赌注。",
"Count Change | Cards |
---|
+1 | 2, 3, 4, 5, 6 |
0 | 7, 8, 9 |
-1 | 10, 'J', 'Q', 'K', 'A' |
",
- "You will write a card counting function. It will receive a card
parameter, which can be a number or a string, and increment or decrement the global count
variable according to the card's value (see table). The function will then return a string with the current count and the string Bet
if the count is positive, or Hold
if the count is zero or negative. The current count and the player's decision (Bet
or Hold
) should be separated by a single space.",
- "Example Output
-3 Hold
5 Bet
",
- "Hint
Do NOT reset count
to 0 when value is 7, 8, or 9.
Do NOT return an array.
Do NOT include quotes (single or double) in the output."
+ "你需要写一个函数实现 21 点算法,它根据参数card
的值来递增或递减变量count
,函数返回一个由当前count
和Bet
(count>0
)或Hold
(count<=0
) 拼接的字符串。注意count
和\"Bet\"
或Hold
应该用空格分开。",
+ "例如:
-3 Hold
5 Bet
",
+ "提示
既然 card 的值为 7、8、9 时,count 值不变,那我们就可以忽略这种情况。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4709,32 +4707,32 @@
],
"tests": [
{
- "text": "Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet
",
- "testString": "assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === \"5 Bet\") {return true;} return false; })(), 'Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet
');"
+ "text": "Cards Sequence 2, 3, 4, 5, 6 应该返回5 Bet
",
+ "testString": "assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === \"5 Bet\") {return true;} return false; })(), 'Cards Sequence 2, 3, 4, 5, 6 应该返回 5 Bet
');"
},
{
- "text": "Cards Sequence 7, 8, 9 should return 0 Hold
",
- "testString": "assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === \"0 Hold\") {return true;} return false; })(), 'Cards Sequence 7, 8, 9 should return 0 Hold
');"
+ "text": "Cards Sequence 7, 8, 9 应该返回 0 Hold
",
+ "testString": "assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === \"0 Hold\") {return true;} return false; })(), 'Cards Sequence 7, 8, 9 应该返回 0 Hold
');"
},
{
- "text": "Cards Sequence 10, J, Q, K, A should return -5 Hold
",
- "testString": "assert((function(){ count = 0; cc(10);cc('J');cc('Q');cc('K');var out = cc('A'); if(out === \"-5 Hold\") {return true;} return false; })(), 'Cards Sequence 10, J, Q, K, A should return -5 Hold
');"
+ "text": "Cards Sequence 10, J, Q, K, A 应该返回 -5 Hold
",
+ "testString": "assert((function(){ count = 0; cc(10);cc('J');cc('Q');cc('K');var out = cc('A'); if(out === \"-5 Hold\") {return true;} return false; })(), 'Cards Sequence 10, J, Q, K, A 应该返回 -5 Hold
');"
},
{
- "text": "Cards Sequence 3, 7, Q, 8, A should return -1 Hold
",
- "testString": "assert((function(){ count = 0; cc(3);cc(7);cc('Q');cc(8);var out = cc('A'); if(out === \"-1 Hold\") {return true;} return false; })(), 'Cards Sequence 3, 7, Q, 8, A should return -1 Hold
');"
+ "text": "Cards Sequence 3, 7, Q, 8, A 应该返回 -1 Hold
",
+ "testString": "assert((function(){ count = 0; cc(3);cc(7);cc('Q');cc(8);var out = cc('A'); if(out === \"-1 Hold\") {return true;} return false; })(), 'Cards Sequence 3, 7, Q, 8, A 应该返回 -1 Hold
');"
},
{
- "text": "Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
",
- "testString": "assert((function(){ count = 0; cc(2);cc('J');cc(9);cc(2);var out = cc(7); if(out === \"1 Bet\") {return true;} return false; })(), 'Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
');"
+ "text": "Cards Sequence 2, J, 9, 2, 7 应该返回 1 Bet
",
+ "testString": "assert((function(){ count = 0; cc(2);cc('J');cc(9);cc(2);var out = cc(7); if(out === \"1 Bet\") {return true;} return false; })(), 'Cards Sequence 2, J, 9, 2, 7 应该返回 1 Bet
');"
},
{
- "text": "Cards Sequence 2, 2, 10 should return 1 Bet
",
- "testString": "assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === \"1 Bet\") {return true;} return false; })(), 'Cards Sequence 2, 2, 10 should return 1 Bet
');"
+ "text": "Cards Sequence 2, 2, 10 应该返回 1 Bet
",
+ "testString": "assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === \"1 Bet\") {return true;} return false; })(), 'Cards Sequence 2, 2, 10 应该返回 1 Bet
');"
},
{
- "text": "Cards Sequence 3, 2, A, 10, K should return -1 Hold
",
- "testString": "assert((function(){ count = 0; cc(3);cc(2);cc('A');cc(10);var out = cc('K'); if(out === \"-1 Hold\") {return true;} return false; })(), 'Cards Sequence 3, 2, A, 10, K should return -1 Hold
');"
+ "text": "Cards Sequence 3, 2, A, 10, K 应该返回 -1 Hold
",
+ "testString": "assert((function(){ count = 0; cc(3);cc(2);cc('A');cc(10);var out = cc('K'); if(out === \"-1 Hold\") {return true;} return false; })(), 'Cards Sequence 3, 2, A, 10, K 应该返回 -1 Hold
');"
}
],
"challengeType": 1,
@@ -4747,15 +4745,15 @@
"var count = 0;",
"",
"function cc(card) {",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
" ",
" return \"Change Me\";",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
"}",
"",
- "// Add/remove calls to test your function.",
- "// Note: Only the last will display",
+ "// 你可以在这里添加/删除 cc 方法的调用来测试结果",
+ "// 提示: 左边只会显示最后一次执行的返回值",
"cc(2); cc(3); cc(7); cc('K'); cc('A');"
],
"head": [],
@@ -4767,41 +4765,41 @@
"id": "56bbb991ad1ed5201cd392d0",
"title": "Build JavaScript Objects",
"description": [
- "You may have heard the term object
before.",
- "Objects are similar to arrays
, except that instead of using indexes to access and modify their data, you access the data in objects through what are called properties
.",
- "Objects are useful for storing data in a structured way, and can represent real world objects, like a cat.",
- "Here's a sample cat object:",
+ "你之前可能听说过对象object
。",
+ "对象和数组很相似,数组是通过索引来访问和修改数据,对象是通过属性来访问和修改数据的。",
+ "对象适合用来存储结构化数据,就和真实世界的对象一模一样,比如一只猫。",
+ "这是一个对象的示例:",
"var cat = {
\"name\": \"Whiskers\",
\"legs\": 4,
\"tails\": 1,
\"enemies\": [\"Water\", \"Dogs\"]
};
",
- "In this example, all the properties are stored as strings, such as - \"name\"
, \"legs\"
, and \"tails\"
. However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows:",
+ "在这个示例中所有的属性以字符串的形式储存,例如 - \"name\"
, \"legs\"
,和\"tails\"
。但是,你也可以使用数字作为属性。你甚至可以省略单个字符串属性的引号,如下所示:",
"var anotherObject = {
make: \"Ford\",
5: \"five\",
\"model\": \"focus\"
};
",
- "However, if your object has any non-string properties, JavaScript will automatically typecast them as strings.",
+ "但是,如果你的对象具有任何非字符串属性,JavaScript 将自动将它们作为字符串进行类型转换。",
"
",
- "Make an object that represents a dog called myDog
which contains the properties \"name\"
(a string), \"legs\"
, \"tails\"
and \"friends\"
.",
- "You can set these object properties to whatever values you want, as long \"name\"
is a string, \"legs\"
and \"tails\"
are numbers, and \"friends\"
is an array."
+ "创建一个叫做myDog
的对象,它里面有这些属性:名称\"name\"
、腿\"legs\"
,尾巴\"tails\"
、朋友\"friends\"
。",
+ "你可以设置对象属性为任何你想要的值,只要\"name\"
是字符串、\"legs\"
和\"tails\"
是数字、\"friends\"
是数组。"
],
"solutions": [
"var myDog = {\n \"name\": \"Camper\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"everything!\"] \n};"
],
"tests": [
{
- "text": "myDog
should contain the property name
and it should be a string
.",
- "testString": "assert((function(z){if(z.hasOwnProperty(\"name\") && z.name !== undefined && typeof z.name === \"string\"){return true;}else{return false;}})(myDog), 'myDog
should contain the property name
and it should be a string
.');"
+ "text": "myDog
应该包含name
属性,并且是一个字符串string
.",
+ "testString": "assert((function(z){if(z.hasOwnProperty(\"name\") && z.name !== undefined && typeof z.name === \"string\"){return true;}else{return false;}})(myDog), 'myDog
应该包含name
属性,并且是一个字符串string
.');"
},
{
- "text": "myDog
should contain the property legs
and it should be a number
.",
- "testString": "assert((function(z){if(z.hasOwnProperty(\"legs\") && z.legs !== undefined && typeof z.legs === \"number\"){return true;}else{return false;}})(myDog), 'myDog
should contain the property legs
and it should be a number
.');"
+ "text": "myDog
应该包含legs
属性,并且是一个数字number
.",
+ "testString": "assert((function(z){if(z.hasOwnProperty(\"legs\") && z.legs !== undefined && typeof z.legs === \"number\"){return true;}else{return false;}})(myDog), 'myDog
应该包含legs
属性,并且是一个数字number
.');"
},
{
- "text": "myDog
should contain the property tails
and it should be a number
.",
- "testString": "assert((function(z){if(z.hasOwnProperty(\"tails\") && z.tails !== undefined && typeof z.tails === \"number\"){return true;}else{return false;}})(myDog), 'myDog
should contain the property tails
and it should be a number
.');"
+ "text": "myDog
应该包含tails
属性,并且是一个数字number
.",
+ "testString": "assert((function(z){if(z.hasOwnProperty(\"tails\") && z.tails !== undefined && typeof z.tails === \"number\"){return true;}else{return false;}})(myDog), 'myDog
应该包含tails
属性,并且是一个数字number
.');"
},
{
- "text": "myDog
should contain the property friends
and it should be an array
.",
- "testString": "assert((function(z){if(z.hasOwnProperty(\"friends\") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), 'myDog
should contain the property friends
and it should be an array
.');"
+ "text": "myDog
应该包含friends
属性,并且是一个数组array
.",
+ "testString": "assert((function(z){if(z.hasOwnProperty(\"friends\") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), 'myDog
应该包含friends
属性,并且是一个数组array
.');"
},
{
- "text": "myDog
should only contain all the given properties.",
- "testString": "assert((function(z){return Object.keys(z).length === 4;})(myDog), 'myDog
should only contain all the given properties.');"
+ "text": "myDog
应该只包含给出的属性",
+ "testString": "assert((function(z){return Object.keys(z).length === 4;})(myDog), 'myDog
应该只包含给出的属性');"
}
],
"challengeType": 1,
@@ -4811,7 +4809,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourDog = {",
" \"name\": \"Camper\",",
" \"legs\": 4,",
@@ -4819,7 +4817,7 @@
" \"friends\": [\"everything!\"]",
"};",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
"var myDog = {",
" ",
@@ -4839,12 +4837,12 @@
"id": "56533eb9ac21ba0edf2244c7",
"title": "Accessing Object Properties with Dot Notation",
"description": [
- "There are two ways to access the properties of an object: dot notation (.
) and bracket notation ([]
), similar to an array.",
- "Dot notation is what you use when you know the name of the property you're trying to access ahead of time.",
- "Here is a sample of using dot notation (.
) to read an object's property:",
+ "有两种方式访问对象属性,一个是点操作符(.
),一个是中括号操作符([]
)。",
+ "当你知道属性的名称的时候,使用点操作符。",
+ "这是一个使用点操作符读取对象属性的例子:",
"var myObj = {
prop1: \"val1\",
prop2: \"val2\"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
",
"
",
- "Read in the property values of testObj
using dot notation. Set the variable hatValue
equal to the object's property hat
and set the variable shirtValue
equal to the object's property shirt
."
+ "通过点操作符读取对象testObj
,把hat
的属性值赋给变量hatValue
,把shirt
的属性值赋给shirtValue
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4852,24 +4850,24 @@
],
"tests": [
{
- "text": "hatValue
should be a string",
- "testString": "assert(typeof hatValue === 'string' , 'hatValue
should be a string');"
+ "text": "hatValue
应该是一个字符串",
+ "testString": "assert(typeof hatValue === 'string' , 'hatValue
应该是一个字符串');"
},
{
- "text": "The value of hatValue
should be \"ballcap\"
",
- "testString": "assert(hatValue === 'ballcap' , 'The value of hatValue
should be \"ballcap\"
');"
+ "text": "hatValue
的值应该是\"ballcap\"
",
+ "testString": "assert(hatValue === 'ballcap' , 'hatValue
的值应该是\"ballcap\"
');"
},
{
- "text": "shirtValue
should be a string",
- "testString": "assert(typeof shirtValue === 'string' , 'shirtValue
should be a string');"
+ "text": "shirtValue
应该是一个字符串",
+ "testString": "assert(typeof shirtValue === 'string' , 'shirtValue
应该是一个字符串');"
},
{
- "text": "The value of shirtValue
should be \"jersey\"
",
- "testString": "assert(shirtValue === 'jersey' , 'The value of shirtValue
should be \"jersey\"
');"
+ "text": "shirtValue
的值应该是\"jersey\"
",
+ "testString": "assert(shirtValue === 'jersey' , 'shirtValue
的值应该是\"jersey\"
');"
},
{
- "text": "You should use dot notation twice",
- "testString": "assert(code.match(/testObj\\.\\w+/g).length > 1, 'You should use dot notation twice');"
+ "text": "你应该使用点操作符两次",
+ "testString": "assert(code.match(/testObj\\.\\w+/g).length > 1, '你应该使用点操作符两次');"
}
],
"challengeType": 1,
@@ -4879,17 +4877,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var testObj = {",
" \"hat\": \"ballcap\",",
" \"shirt\": \"jersey\",",
" \"shoes\": \"cleats\"",
"};",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
- "var hatValue = testObj; // Change this line",
- "var shirtValue = testObj; // Change this line"
+ "var hatValue = testObj; // 请修改这一行",
+ "var shirtValue = testObj; // 请修改这一行"
],
"head": [],
"tail": [
@@ -4902,13 +4900,12 @@
"id": "56533eb9ac21ba0edf2244c8",
"title": "Accessing Object Properties with Bracket Notation",
"description": [
- "The second way to access the properties of an object is bracket notation ([]
). If the property of the object you are trying to access has a space in its name, you will need to use bracket notation.",
- "However, you can still use bracket notation on object properties without spaces.",
- "Here is a sample of using bracket notation to read an object's property:",
+ "第二种访问对象的方式就是中括号操作符([]
),如果你想访问的属性的名称有一个空格,这时你只能使用中括号操作符([]
)。",
+ "这是一个使用中括号操作符([]
)读取对象属性的例子:",
"var myObj = {
\"Space Name\": \"Kirk\",
\"More Space\": \"Spock\",
\"NoSpace\": \"USS Enterprise\"
};
myObj[\"Space Name\"]; // Kirk
myObj['More Space']; // Spock
myObj[\"NoSpace\"]; // USS Enterprise
",
- "Note that property names with spaces in them must be in quotes (single or double).",
+ "提示:属性名称中如果有空格,必须把属性名称用单引号或双引号包裹起来。",
"
",
- "Read the values of the properties \"an entree\"
and \"the drink\"
of testObj
using bracket notation and assign them to entreeValue
and drinkValue
respectively."
+ "用中括号操作符读取对象testObj
的属性\"an entree\"
值和属性\"the drink\"
值,并赋给entreeValue
和drinkValue
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4916,24 +4913,24 @@
],
"tests": [
{
- "text": "entreeValue
should be a string",
- "testString": "assert(typeof entreeValue === 'string' , 'entreeValue
should be a string');"
+ "text": "entreeValue
应该是一个字符串",
+ "testString": "assert(typeof entreeValue === 'string' , 'entreeValue
应该是一个字符串');"
},
{
- "text": "The value of entreeValue
should be \"hamburger\"
",
- "testString": "assert(entreeValue === 'hamburger' , 'The value of entreeValue
should be \"hamburger\"
');"
+ "text": "entreeValue
的值应该是\"hamburger\"
",
+ "testString": "assert(entreeValue === 'hamburger' , 'entreeValue
的值应该是\"hamburger\"
');"
},
{
- "text": "drinkValue
should be a string",
- "testString": "assert(typeof drinkValue === 'string' , 'drinkValue
should be a string');"
+ "text": "drinkValue
应该是一个字符串",
+ "testString": "assert(typeof drinkValue === 'string' , 'drinkValue
应该是一个字符串');"
},
{
- "text": "The value of drinkValue
should be \"water\"
",
- "testString": "assert(drinkValue === 'water' , 'The value of drinkValue
should be \"water\"
');"
+ "text": "drinkValue
的值应该是\"water\"
",
+ "testString": "assert(drinkValue === 'water' , 'drinkValue
的值应该是\"water\"
');"
},
{
- "text": "You should use bracket notation twice",
- "testString": "assert(code.match(/testObj\\s*?\\[('|\")[^'\"]+\\1\\]/g).length > 1, 'You should use bracket notation twice');"
+ "text": "你应该使用中括号两次",
+ "testString": "assert(code.match(/testObj\\s*?\\[('|\")[^'\"]+\\1\\]/g).length > 1, '你应该使用中括号两次');"
}
],
"challengeType": 1,
@@ -4944,17 +4941,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var testObj = {",
" \"an entree\": \"hamburger\",",
" \"my side\": \"veggies\",",
" \"the drink\": \"water\"",
"};",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
- "var entreeValue = testObj; // Change this line",
- "var drinkValue = testObj; // Change this line"
+ "var entreeValue = testObj; // 请修改这一行",
+ "var drinkValue = testObj; // 请修改这一行"
],
"head": [],
"tail": [
@@ -4967,14 +4964,14 @@
"id": "56533eb9ac21ba0edf2244c9",
"title": "Accessing Object Properties with Variables",
"description": [
- "Another use of bracket notation on objects is to access a property which is stored as the value of a variable. This can be very useful for iterating through an object's properties or when accessing a lookup table.",
- "Here is an example of using a variable to access a property:",
+ "中括号操作符的另一个使用方式是用变量来访问一个属性。当你需要遍历对象的属性列表或查表时,这种方式极为有用。",
+ "这有一个使用变量来访问属性的例子:",
"var dogs = {
Fido: \"Mutt\",\n Hunter: \"Doberman\",\n Snoopie: \"Beagle\"
};
var myDog = \"Hunter\";
var myBreed = dogs[myDog];
console.log(myBreed); // \"Doberman\"
",
- "Another way you can use this concept is when the property's name is collected dynamically during the program execution, as follows:",
+ "还有更多:",
"var someObj = {
propName: \"John\"
};
function propPrefix(str) {
var s = \"prop\";
return s + str;
}
var someProp = propPrefix(\"Name\"); // someProp now holds the value 'propName'
console.log(someObj[someProp]); // \"John\"
",
- "Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name.",
+ "提示:当我们通过变量名访问属性的时候,不需要给变量名包裹引号。因为实际上我们使用的是变量的值,而不是变量的名称。",
"
",
- "Use the playerNumber
variable to look up player 16
in testObj
using bracket notation. Then assign that name to the player
variable."
+ "使用变量playerNumber
,通过中括号操作符找到testObj
中playerNumber
为16
的值。然后把名字赋给变量player
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -4982,28 +4979,28 @@
],
"tests": [
{
- "text": "playerNumber
should be a number",
- "testString": "assert(typeof playerNumber === 'number', 'playerNumber
should be a number');"
+ "text": "playerNumber
应该是一个数字",
+ "testString": "assert(typeof playerNumber === 'number', 'playerNumber
应该是一个数字');"
},
{
- "text": "The variable player
should be a string",
- "testString": "assert(typeof player === 'string', 'The variable player
should be a string');"
+ "text": "变量player
应该是一个字符串",
+ "testString": "assert(typeof player === 'string', '变量player
应该是一个字符串');"
},
{
- "text": "The value of player
should be \"Montana\"",
- "testString": "assert(player === 'Montana', 'The value of player
should be \"Montana\"');"
+ "text": "player
点值应该是 \"Montana\"",
+ "testString": "assert(player === 'Montana', 'player
点值应该是 \"Montana\"');"
},
{
- "text": "You should use bracket notation to access testObj
",
- "testString": "assert(/testObj\\s*?\\[.*?\\]/.test(code),'You should use bracket notation to access testObj
');"
+ "text": "你应该使用中括号访问testObj
",
+ "testString": "assert(/testObj\\s*?\\[.*?\\]/.test(code),'你应该使用中括号访问testObj
');"
},
{
- "text": "You should not assign the value Montana
to the variable player
directly.",
- "testString": "assert(!code.match(/player\\s*=\\s*\"|\\'\\s*Montana\\s*\"|\\'\\s*;/gi),'You should not assign the value Montana
to the variable player
directly.');"
+ "text": "你不应该直接将Montana
赋给player
",
+ "testString": "assert(!code.match(/player\\s*=\\s*\"|\\'\\s*Montana\\s*\"|\\'\\s*;/gi),'你不应该直接将Montana
赋给player
');"
},
{
- "text": "You should be using the variable playerNumber
in your bracket notation",
- "testString": "assert(/testObj\\s*?\\[\\s*playerNumber\\s*\\]/.test(code),'You should be using the variable playerNumber
in your bracket notation');"
+ "text": "你应该在中括号中使用playerNumber
变量",
+ "testString": "assert(/testObj\\s*?\\[\\s*playerNumber\\s*\\]/.test(code),'你应该在中括号中使用playerNumber
变量');"
}
],
"challengeType": 1,
@@ -5014,17 +5011,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var testObj = {",
" 12: \"Namath\",",
" 16: \"Montana\",",
" 19: \"Unitas\"",
"};",
"",
- "// Only change code below this line;",
+ "// 请把你的代码写在这条注释以下;",
"",
- "var playerNumber; // Change this Line",
- "var player = testObj; // Change this Line"
+ "var playerNumber; // 请修改这一行",
+ "var player = testObj; // 请修改这一行"
],
"head": [],
"tail": [
@@ -5037,27 +5034,27 @@
"id": "56bbb991ad1ed5201cd392d1",
"title": "Updating Object Properties",
"description": [
- "After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.",
- "For example, let's look at ourDog
:",
+ "当你创建了一个对象后,你可以用点操作符或中括号操作符来更新对象的属性。",
+ "举个例子,让我们看看ourDog
:",
"var ourDog = {
\"name\": \"Camper\",
\"legs\": 4,
\"tails\": 1,
\"friends\": [\"everything!\"]
};
",
- "Since he's a particularly happy dog, let's change his name to \"Happy Camper\". Here's how we update his object's name property:",
+ "让我们更改它的名称为 \"Happy Camper\",这有两种方式来更新对象的name
属性:",
"ourDog.name = \"Happy Camper\";
or",
"ourDog[\"name\"] = \"Happy Camper\";
",
"Now when we evaluate ourDog.name
, instead of getting \"Camper\", we'll get his new name, \"Happy Camper\".",
"
",
- "Update the myDog
object's name property. Let's change her name from \"Coder\" to \"Happy Coder\". You can use either dot or bracket notation."
+ "更新myDog
对象的name
属性,让它的名字从 \"Coder\" 变成 \"Happy Coder\"。"
],
"solutions": [
"var myDog = {\n \"name\": \"Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"freeCodeCamp Campers\"]\n};\nmyDog.name = \"Happy Coder\";"
],
"tests": [
{
- "text": "Update myDog
's \"name\"
property to equal \"Happy Coder\".",
- "testString": "assert(/happy coder/gi.test(myDog.name), 'Update myDog
's \"name\"
property to equal \"Happy Coder\".');"
+ "text": "更新myDog
的\"name\"
属性, 使其等于 \"Happy Coder\"",
+ "testString": "assert(/happy coder/gi.test(myDog.name), '更新myDog
的\"name\"
属性, 使其等于 \"Happy Coder\"');"
},
{
- "text": "Do not edit the myDog
definition",
- "testString": "assert(/\"name\": \"Coder\"/.test(code), 'Do not edit the myDog
definition');"
+ "text": "不要修改myDog
的定义",
+ "testString": "assert(/\"name\": \"Coder\"/.test(code), '不要修改myDog
的定义');"
}
],
"challengeType": 1,
@@ -5067,7 +5064,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourDog = {",
" \"name\": \"Camper\",",
" \"legs\": 4,",
@@ -5077,7 +5074,7 @@
"",
"ourDog.name = \"Happy Camper\";",
"",
- "// Setup",
+ "// 初始化变量",
"var myDog = {",
" \"name\": \"Coder\",",
" \"legs\": 4,",
@@ -5085,7 +5082,7 @@
" \"friends\": [\"freeCodeCamp Campers\"]",
"};",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5100,26 +5097,26 @@
"id": "56bbb991ad1ed5201cd392d2",
"title": "Add New Properties to a JavaScript Object",
"description": [
- "You can add new properties to existing JavaScript objects the same way you would modify them.",
- "Here's how we would add a \"bark\"
property to ourDog
:",
+ "你也可以像更改属性一样给对象添加属性。",
+ "看看我们是如何给ourDog
添加\"bark\"
属性:",
"ourDog.bark = \"bow-wow\";
",
- "or",
+ "或者",
"ourDog[\"bark\"] = \"bow-wow\";
",
- "Now when we evaluate ourDog.bark
, we'll get his bark, \"bow-wow\".",
+ "现在当我们访问ourDog.bark
时会得到 ourDog 的 bark 值 \"bow-wow\".",
"
",
- "Add a \"bark\"
property to myDog
and set it to a dog sound, such as \"woof\". You may use either dot or bracket notation."
+ "给myDog
添加一个\"bark\"
属性,设置它的值为狗的声音,例如:\"woof\"。"
],
"solutions": [
"var myDog = {\n \"name\": \"Happy Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"freeCodeCamp Campers\"]\n};\nmyDog.bark = \"Woof Woof\";"
],
"tests": [
{
- "text": "Add the property \"bark\"
to myDog
.",
- "testString": "assert(myDog.bark !== undefined, 'Add the property \"bark\"
to myDog
.');"
+ "text": "给myDog
添加\"bark\"
属性",
+ "testString": "assert(myDog.bark !== undefined, '给myDog
添加\"bark\"
属性');"
},
{
- "text": "Do not add \"bark\"
to the setup section",
- "testString": "assert(!/bark[^\\n]:/.test(code), 'Do not add \"bark\"
to the setup section');"
+ "text": "不能在初始化 myDog 的时候添加\"bark\"
属性",
+ "testString": "assert(!/bark[^\\n]:/.test(code), '不能在初始化 myDog 的时候添加\"bark\"
属性');"
}
],
"challengeType": 1,
@@ -5129,7 +5126,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourDog = {",
" \"name\": \"Camper\",",
" \"legs\": 4,",
@@ -5139,7 +5136,7 @@
"",
"ourDog.bark = \"bow-wow\";",
"",
- "// Setup",
+ "// 初始化变量",
"var myDog = {",
" \"name\": \"Happy Coder\",",
" \"legs\": 4,",
@@ -5147,7 +5144,7 @@
" \"friends\": [\"freeCodeCamp Campers\"]",
"};",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
""
],
"head": [],
@@ -5161,22 +5158,22 @@
"id": "56bbb991ad1ed5201cd392d3",
"title": "Delete Properties from a JavaScript Object",
"description": [
- "We can also delete properties from objects like this:",
+ "我们同样可以删除对象的属性,例如:",
"delete ourDog.bark;
",
"
",
- "Delete the \"tails\"
property from myDog
. You may use either dot or bracket notation."
+ "删除myDog
对象的\"tails\"
属性。"
],
"solutions": [
"var ourDog = {\n \"name\": \"Camper\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"everything!\"],\n \"bark\": \"bow-wow\"\n};\nvar myDog = {\n \"name\": \"Happy Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"freeCodeCamp Campers\"],\n \"bark\": \"woof\"\n};\ndelete myDog.tails;"
],
"tests": [
{
- "text": "Delete the property \"tails\"
from myDog
.",
- "testString": "assert(typeof myDog === \"object\" && myDog.tails === undefined, 'Delete the property \"tails\"
from myDog
.');"
+ "text": "从myDog
中删除\"tails\"
属性",
+ "testString": "assert(typeof myDog === \"object\" && myDog.tails === undefined, '从myDog
中删除\"tails\"
属性');"
},
{
- "text": "Do not modify the myDog
setup",
- "testString": "assert(code.match(/\"tails\": 1/g).length > 1, 'Do not modify the myDog
setup');"
+ "text": "不要修改myDog
的初始化",
+ "testString": "assert(code.match(/\"tails\": 1/g).length > 1, '不要修改myDog
的初始化');"
}
],
"challengeType": 1,
@@ -5186,7 +5183,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourDog = {",
" \"name\": \"Camper\",",
" \"legs\": 4,",
@@ -5197,7 +5194,7 @@
"",
"delete ourDog.bark;",
"",
- "// Setup",
+ "// 初始化变量",
"var myDog = {",
" \"name\": \"Happy Coder\",",
" \"legs\": 4,",
@@ -5206,7 +5203,7 @@
" \"bark\": \"woof\"",
"};",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5221,11 +5218,11 @@
"id": "56533eb9ac21ba0edf2244ca",
"title": "Using Objects for Lookups",
"description": [
- "Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to \"lookup\" values rather than a switch
statement or an if/else
chain. This is most useful when you know that your input data is limited to a certain range.",
- "Here is an example of a simple reverse alphabet lookup:",
+ "对象和字典一样,可以用来存储键/值对。如果你的数据跟对象一样,你可以用对象来查找你想要的值,而不是使用switch或if/else语句。当你知道你的输入数据在某个范围时,这种查找方式极为有效。",
+ "这是简单的反向字母表:",
"var alpha = {
1:\"Z\",
2:\"Y\",
3:\"X\",
4:\"W\",
...
24:\"C\",
25:\"B\",
26:\"A\"
};
alpha[2]; // \"Y\"
alpha[24]; // \"C\"
var value = 2;
alpha[value]; // \"Y\"
",
"
",
- "Convert the switch statement into an object called lookup
. Use it to look up val
and assign the associated string to the result
variable."
+ "把 switch 语句转化为lookup
对象。使用它来查找val
属性的值,并赋值给result
变量。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5233,40 +5230,40 @@
],
"tests": [
{
- "text": "phoneticLookup(\"alpha\")
should equal \"Adams\"
",
- "testString": "assert(phoneticLookup(\"alpha\") === 'Adams', 'phoneticLookup(\"alpha\")
should equal \"Adams\"
');"
+ "text": "phoneticLookup(\"alpha\")
应该等于\"Adams\"
",
+ "testString": "assert(phoneticLookup(\"alpha\") === 'Adams', 'phoneticLookup(\"alpha\")
应该等于\"Adams\"
');"
},
{
- "text": "phoneticLookup(\"bravo\")
should equal \"Boston\"
",
- "testString": "assert(phoneticLookup(\"bravo\") === 'Boston', 'phoneticLookup(\"bravo\")
should equal \"Boston\"
');"
+ "text": "phoneticLookup(\"bravo\")
应该等于\"Boston\"
",
+ "testString": "assert(phoneticLookup(\"bravo\") === 'Boston', 'phoneticLookup(\"bravo\")
应该等于\"Boston\"
');"
},
{
- "text": "phoneticLookup(\"charlie\")
should equal \"Chicago\"
",
- "testString": "assert(phoneticLookup(\"charlie\") === 'Chicago', 'phoneticLookup(\"charlie\")
should equal \"Chicago\"
');"
+ "text": "phoneticLookup(\"charlie\")
应该等于\"Chicago\"
",
+ "testString": "assert(phoneticLookup(\"charlie\") === 'Chicago', 'phoneticLookup(\"charlie\")
应该等于\"Chicago\"
');"
},
{
- "text": "phoneticLookup(\"delta\")
should equal \"Denver\"
",
- "testString": "assert(phoneticLookup(\"delta\") === 'Denver', 'phoneticLookup(\"delta\")
should equal \"Denver\"
');"
+ "text": "phoneticLookup(\"delta\")
应该等于\"Denver\"
",
+ "testString": "assert(phoneticLookup(\"delta\") === 'Denver', 'phoneticLookup(\"delta\")
应该等于\"Denver\"
');"
},
{
- "text": "phoneticLookup(\"echo\")
should equal \"Easy\"
",
- "testString": "assert(phoneticLookup(\"echo\") === 'Easy', 'phoneticLookup(\"echo\")
should equal \"Easy\"
');"
+ "text": "phoneticLookup(\"echo\")
应该等于\"Easy\"
",
+ "testString": "assert(phoneticLookup(\"echo\") === 'Easy', 'phoneticLookup(\"echo\")
应该等于\"Easy\"
');"
},
{
- "text": "phoneticLookup(\"foxtrot\")
should equal \"Frank\"
",
- "testString": "assert(phoneticLookup(\"foxtrot\") === 'Frank', 'phoneticLookup(\"foxtrot\")
should equal \"Frank\"
');"
+ "text": "phoneticLookup(\"foxtrot\")
应该等于\"Frank\"
",
+ "testString": "assert(phoneticLookup(\"foxtrot\") === 'Frank', 'phoneticLookup(\"foxtrot\")
应该等于\"Frank\"
');"
},
{
- "text": "phoneticLookup(\"\")
should equal undefined
",
- "testString": "assert(typeof phoneticLookup(\"\") === 'undefined', 'phoneticLookup(\"\")
should equal undefined
');"
+ "text": "phoneticLookup(\"\")
应该等于undefined
",
+ "testString": "assert(typeof phoneticLookup(\"\") === 'undefined', 'phoneticLookup(\"\")
应该等于undefined
');"
},
{
- "text": "You should not modify the return
statement",
- "testString": "assert(code.match(/return\\sresult;/), 'You should not modify the return
statement');"
+ "text": "请不要修改return
语句",
+ "testString": "assert(code.match(/return\\sresult;/), '请不要修改return
语句');"
},
{
- "text": "You should not use case
, switch
, or if
statements",
- "testString": "assert(!/case|switch|if/g.test(code), 'You should not use case
, switch
, or if
statements'); "
+ "text": "请不要使用case
,switch
,或if
语句",
+ "testString": "assert(!/case|switch|if/g.test(code), '请不要使用case
,switch
,或if
语句'); "
}
],
"challengeType": 1,
@@ -5276,11 +5273,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"function phoneticLookup(val) {",
" var result = \"\";",
"",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" switch(val) {",
" case \"alpha\": ",
" result = \"Adams\";",
@@ -5301,11 +5298,11 @@
" result = \"Frank\";",
" }",
"",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return result;",
"}",
"",
- "// Change this value to test",
+ "// 你可以修改这一行来测试你的代码",
"phoneticLookup(\"charlie\");"
],
"head": [],
@@ -5317,11 +5314,11 @@
"id": "567af2437cbaa8c51670a16c",
"title": "Testing Objects for Properties",
"description": [
- "Sometimes it is useful to check if the property of a given object exists or not. We can use the .hasOwnProperty(propname)
method of objects to determine if that object has the given property name. .hasOwnProperty()
returns true
or false
if the property is found or not.",
- "Example",
+ "有时检查一个对象属性是否存在是非常有用的,我们可以用.hasOwnProperty(propname)
方法来检查对象是否有该属性。如果有返回true
,反之返回false
。",
+ "示例",
"var myObj = {
top: \"hat\",
bottom: \"pants\"
};
myObj.hasOwnProperty(\"top\"); // true
myObj.hasOwnProperty(\"middle\"); // false
",
"
",
- "Modify the function checkObj
to test myObj
for checkProp
. If the property is found, return that property's value. If not, return \"Not Found\"
."
+ "修改函数checkObj
检查myObj
是否有checkProp
属性,如果属性存在,返回属性对应的值,如果不存在,返回\"Not Found\"
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5329,16 +5326,16 @@
],
"tests": [
{
- "text": "checkObj(\"gift\")
should return \"pony\"
.",
- "testString": "assert(checkObj(\"gift\") === \"pony\", 'checkObj(\"gift\")
should return \"pony\"
.');"
+ "text": "checkObj(\"gift\")
应该返回\"pony\"
.",
+ "testString": "assert(checkObj(\"gift\") === \"pony\", 'checkObj(\"gift\")
应该返回 \"pony\"
.');"
},
{
- "text": "checkObj(\"pet\")
should return \"kitten\"
.",
- "testString": "assert(checkObj(\"pet\") === \"kitten\", 'checkObj(\"pet\")
should return \"kitten\"
.');"
+ "text": "checkObj(\"pet\")
应该返回\"kitten\"
.",
+ "testString": "assert(checkObj(\"pet\") === \"kitten\", 'checkObj(\"pet\")
应该返回 \"kitten\"
.');"
},
{
- "text": "checkObj(\"house\")
should return \"Not Found\"
.",
- "testString": "assert(checkObj(\"house\") === \"Not Found\", 'checkObj(\"house\")
should return \"Not Found\"
.');"
+ "text": "checkObj(\"house\")
应该返回\"Not Found\"
.",
+ "testString": "assert(checkObj(\"house\") === \"Not Found\", 'checkObj(\"house\")
应该返回\"Not Found\"
.');"
}
],
"challengeType": 1,
@@ -5348,7 +5345,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myObj = {",
" gift: \"pony\",",
" pet: \"kitten\",",
@@ -5356,12 +5353,12 @@
"};",
"",
"function checkObj(checkProp) {",
- " // Your Code Here",
+ " // 请把你的代码写在这条注释以下",
" ",
" return \"Change Me!\";",
"}",
"",
- "// Test your code by modifying these values",
+ "// 你可以修改这一行来测试你的代码",
"checkObj(\"gift\");"
],
"head": [],
@@ -5373,16 +5370,16 @@
"id": "56533eb9ac21ba0edf2244cb",
"title": "Manipulating Complex Objects",
"description": [
- "Sometimes you may want to store data in a flexible Data Structure. A JavaScript object is one way to handle flexible data. They allow for arbitrary combinations of strings, numbers, booleans, arrays, functions, and objects.",
- "Here's an example of a complex data structure:",
+ "有时你可能希望将数据存储在灵活的数据结构中。JavaScript 对象是处理灵活数据的一种方法。它可以储存字符串,数字,布尔值,函数,和对象以及这些值的任意组合。",
+ "这是一个复杂数据结构的示例:",
"var ourMusic = [
{
\"artist\": \"Daft Punk\",
\"title\": \"Homework\",
\"release_year\": 1997,
\"formats\": [
\"CD\",
\"Cassette\",
\"LP\"
],
\"gold\": true
}
];
",
- "This is an array which contains one object inside. The object has various pieces of metadata about an album. It also has a nested \"formats\"
array. If you want to add more album records, you can do this by adding records to the top level array.",
- "Objects hold data in a property, which has a key-value format. In the example above, \"artist\": \"Daft Punk\"
is a property that has a key of \"artist\"
and a value of \"Daft Punk\"
.",
- "JavaScript Object Notation or JSON
is a related data interchange format used to store data.",
+ "这是一个对象数组,并且对象有各种关于专辑的 详细信息。它也有一个嵌套的formats
的数组。附加专辑记录可以被添加到数组的最上层。",
+ "对象将数据以一种键-值对的形式保存。在上面的示例中,\"artist\": \"Daft Punk\"
是一个具有\"artist\"
键和\"Daft Punk\"
值的属性。",
+ "JavaScript Object Notation 简称JSON
是用于存储数据的相关数据交换格式。",
"{
\"artist\": \"Daft Punk\",
\"title\": \"Homework\",
\"release_year\": 1997,
\"formats\": [
\"CD\",
\"Cassette\",
\"LP\"
],
\"gold\": true
}
",
- "Note
You will need to place a comma after every object in the array, unless it is the last object in the array.",
+ "提示
数组中有多个 JSON 对象的时候,对象与对象之间要用逗号隔开。",
"
",
- "Add a new album to the myMusic
array. Add artist
and title
strings, release_year
number, and a formats
array of strings."
+ "添加一个新专辑到myMusic
的JSON对象。添加artist
和title
字符串,release_year
数字和formats
字符串数组。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5390,40 +5387,40 @@
],
"tests": [
{
- "text": "myMusic
should be an array",
- "testString": "assert(Array.isArray(myMusic), 'myMusic
should be an array');"
+ "text": "myMusic
应该是一个数组",
+ "testString": "assert(Array.isArray(myMusic), 'myMusic
应该是一个数组');"
},
{
- "text": "myMusic
should have at least two elements",
- "testString": "assert(myMusic.length > 1, 'myMusic
should have at least two elements');"
+ "text": "myMusic
应该至少包含两个元素",
+ "testString": "assert(myMusic.length > 1, 'myMusic
应该至少包含两个元素');"
},
{
- "text": "myMusic[1]
should be an object",
- "testString": "assert(typeof myMusic[1] === 'object', 'myMusic[1]
should be an object');"
+ "text": "myMusic[1]
应该是一个对象",
+ "testString": "assert(typeof myMusic[1] === 'object', 'myMusic[1]
应该是一个对象');"
},
{
- "text": "myMusic[1]
should have at least 4 properties",
- "testString": "assert(Object.keys(myMusic[1]).length > 3, 'myMusic[1]
should have at least 4 properties');"
+ "text": "myMusic[1]
至少要包含四个属性",
+ "testString": "assert(Object.keys(myMusic[1]).length > 3, 'myMusic[1]
至少要包含四个属性');"
},
{
- "text": "myMusic[1]
should contain an artist
property which is a string",
- "testString": "assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string', 'myMusic[1]
should contain an artist
property which is a string');"
+ "text": "myMusic[1]
应该包含一个类型为字符串的artist
的属性",
+ "testString": "assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string', 'myMusic[1]
应该包含一个类型为字符串的artist
的属性');"
},
{
- "text": "myMusic[1]
should contain a title
property which is a string",
- "testString": "assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string', 'myMusic[1]
should contain a title
property which is a string');"
+ "text": "myMusic[1]
应该包含一个类型为字符串的title
的属性",
+ "testString": "assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string', 'myMusic[1]
应该包含一个类型为字符串的title
的属性');"
},
{
- "text": "myMusic[1]
should contain a release_year
property which is a number",
- "testString": "assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number', 'myMusic[1]
should contain a release_year
property which is a number');"
+ "text": "myMusic[1]
应该包含一个类型为数字的release_year
应该包含一个类型为数字的属性",
+ "testString": "assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number', 'myMusic[1]
应该包含一个类型为数字的release_year
应该包含一个类型为数字的属性');"
},
{
- "text": "myMusic[1]
should contain a formats
property which is an array",
- "testString": "assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats), 'myMusic[1]
should contain a formats
property which is an array');"
+ "text": "myMusic[1]
应该包含一个类型为数组的formats
属性",
+ "testString": "assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats), 'myMusic[1]
应该包含一个类型为数组的formats
属性');"
},
{
- "text": "formats
should be an array of strings with at least two elements",
- "testString": "assert(myMusic[1].formats.every(function(item) { return (typeof item === \"string\")}) && myMusic[1].formats.length > 1, 'formats
should be an array of strings with at least two elements');"
+ "text": "formats
应该是一个至少包含两个字符串元素的数组",
+ "testString": "assert(myMusic[1].formats.every(function(item) { return (typeof item === \"string\")}) && myMusic[1].formats.length > 1, 'formats
应该是一个至少包含两个字符串元素的数组');"
}
],
"challengeType": 1,
@@ -5445,7 +5442,7 @@
" ],",
" \"gold\": true",
" }",
- " // Add record here",
+ " // 请在这里添加专辑",
"];",
""
],
@@ -5460,11 +5457,11 @@
"id": "56533eb9ac21ba0edf2244cc",
"title": "Accessing Nested Objects",
"description": [
- "The sub-properties of objects can be accessed by chaining together the dot or bracket notation.",
- "Here is a nested object:",
+ "通过串联起来的点操作符或中括号操作符来访问对象的嵌套属性。",
+ "下面是一个嵌套的对象:",
"var ourStorage = {
\"desk\": {
\"drawer\": \"stapler\"
},
\"cabinet\": {
\"top drawer\": {
\"folder1\": \"a file\",
\"folder2\": \"secrets\"
},
\"bottom drawer\": \"soda\"
}
};
ourStorage.cabinet[\"top drawer\"].folder2; // \"secrets\"
ourStorage.desk.drawer; // \"stapler\"
",
"
",
- "Access the myStorage
object and assign the contents of the glove box
property to the gloveBoxContents
variable. Use bracket notation for properties with a space in their name."
+ "检索对象myStorage
中嵌套属性glove box
的值。因为属性的名字带有空格,请使用中括号操作符来访问属性的值。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5472,8 +5469,8 @@
],
"tests": [
{
- "text": "gloveBoxContents
should equal \"maps\"",
- "testString": "assert(gloveBoxContents === \"maps\", 'gloveBoxContents
should equal \"maps\"');"
+ "text": "gloveBoxContents
应该等于\"maps\"",
+ "testString": "assert(gloveBoxContents === \"maps\", 'gloveBoxContents
应该等于\"maps\"');"
},
{
"text": "Use dot and bracket notation to access myStorage
",
@@ -5488,7 +5485,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myStorage = {",
" \"car\": {",
" \"inside\": {",
@@ -5501,7 +5498,7 @@
" }",
"};",
"",
- "var gloveBoxContents = undefined; // Change this line",
+ "var gloveBoxContents = undefined; // 请修改这一行",
""
],
"head": [],
@@ -5520,24 +5517,24 @@
"id": "56533eb9ac21ba0edf2244cd",
"title": "Accessing Nested Arrays",
"description": [
- "As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.",
- "Here is an example of how to access a nested array:",
+ "正如我们在前面的例子所见,对象可以嵌套对象和数组。与访问嵌套对象一样,用中括号操作符同样可以访问嵌套数组。",
+ "下面是如何访问嵌套数组的例子:",
"var ourPets = [
{
animalType: \"cat\",
names: [
\"Meowzer\",
\"Fluffy\",
\"Kit-Cat\"
]
},
{
animalType: \"dog\",
names: [
\"Spot\",
\"Bowser\",
\"Frankie\"
]
}
];
ourPets[0].names[1]; // \"Fluffy\"
ourPets[1].names[0]; // \"Spot\"
",
"
",
- "Retrieve the second tree from the variable myPlants
using object dot and array bracket notation."
+ "使用点操作符和中括号操作符来检索变量myPlants
的第二棵树。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "var myPlants = [\n { \n type: \"flowers\",\n list: [\n \"rose\",\n \"tulip\",\n \"dandelion\"\n ]\n },\n {\n type: \"trees\",\n list: [\n \"fir\",\n \"pine\",\n \"birch\"\n ]\n } \n];\n\n// Only change code below this line\n\nvar secondTree = myPlants[1].list[1];"
+ "var myPlants = [\n { \n type: \"flowers\",\n list: [\n \"rose\",\n \"tulip\",\n \"dandelion\"\n ]\n },\n {\n type: \"trees\",\n list: [\n \"fir\",\n \"pine\",\n \"birch\"\n ]\n } \n];\n\n// 请把你的代码写在这条注释以下\n\nvar secondTree = myPlants[1].list[1];"
],
"tests": [
{
- "text": "secondTree
should equal \"pine\"",
- "testString": "assert(secondTree === \"pine\", 'secondTree
should equal \"pine\"');"
+ "text": "secondTree
应该等于 \"pine\"",
+ "testString": "assert(secondTree === \"pine\", 'secondTree
应该等于 \"pine\"');"
},
{
- "text": "Use dot and bracket notation to access myPlants
",
- "testString": "assert(/=\\s*myPlants\\[1\\].list\\[1\\]/.test(code), 'Use dot and bracket notation to access myPlants
');"
+ "text": "使用点操作符和中括号操作符来检索变量myPlants
",
+ "testString": "assert(/=\\s*myPlants\\[1\\].list\\[1\\]/.test(code), '使用点操作符和中括号操作符来检索变量myPlants
');"
}
],
"challengeType": 1,
@@ -5548,7 +5545,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myPlants = [",
" { ",
" type: \"flowers\",",
@@ -5568,9 +5565,9 @@
" } ",
"];",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
- "var secondTree = \"\"; // Change this line",
+ "var secondTree = \"\"; // 请修改这一行",
""
],
"head": [],
@@ -5589,50 +5586,50 @@
"id": "56533eb9ac21ba0edf2244cf",
"title": "Record Collection",
"description": [
- "You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.",
- "Write a function which takes an album's id
(like 2548
), a property prop
(like \"artist\"
or \"tracks\"
), and a value
(like \"Addicted to Love\"
) to modify the data in this collection.",
- "If prop
isn't \"tracks\"
and value
isn't empty (\"\"
), update or set the value
for that record album's property.",
- "Your function must always return the entire collection object.",
- "There are several rules for handling incomplete data:",
- "If prop
is \"tracks\"
but the album doesn't have a \"tracks\"
property, create an empty array before adding the new value to the album's corresponding property.",
- "If prop
is \"tracks\"
and value
isn't empty (\"\"
), push the value
onto the end of the album's existing tracks
array.",
- "If value
is empty (\"\"
), delete the given prop
property from the album.",
- "Hints
Use bracket notation
when accessing object properties with variables.",
- "Push is an array method you can read about on Mozilla Developer Network.",
- "You may refer back to Manipulating Complex Objects Introducing JavaScript Object Notation (JSON) for a refresher."
+ "你将获得一个 JSON 对象,用来表示你的部分音乐专辑收藏。每张专辑都有几个属性和一个唯一的 id 号作为键值。并非所有专辑都有完整的信息。",
+ "写一个功能,获取一个专辑的id
(如2548
),属性prop
(如“code>\"artist\"或\"tracks\"
),以及一个值value
(如\"Addicted to Love\"
)来修改音乐专辑收藏的数据。",
+ "如果属性prop
不是\"tracks\"
且值value
不为空(\"\"
),则更新或设置该专辑属性的值value
。",
+ "你的函数必须始终返回整个音乐专辑集合对象。",
+ "处理不完整数据有几条规则:",
+ "如果属性prop
是\"tracks\"
,但是专辑没有\"tracks\"
属性,则在添加值之前先给\"tracks\"
创建一个空数组。",
+ "如果prop
是\"tracks\"
,并且值value
不为空(\"\"
), 把值value
添加到tracks
数组中。",
+ "如果值value
为空(\"\"
),则删除专辑的这一属性prop
",
+ "提示
使用中括号
当通过变量访问对象的属性的时候.",
+ "Push 是一个数组方法,详情请查看Mozilla Developer Network.",
+ "你可以参考这一节的内容Manipulating Complex Objects复习相关知识。"
],
"releasedOn": "January 1, 2016",
"solutions": [
- "var collection = {\n 2548: {\n album: \"Slippery When Wet\",\n artist: \"Bon Jovi\",\n tracks: [ \n \"Let It Rock\", \n \"You Give Love a Bad Name\" \n ]\n },\n 2468: {\n album: \"1999\",\n artist: \"Prince\",\n tracks: [ \n \"1999\", \n \"Little Red Corvette\" \n ]\n },\n 1245: {\n artist: \"Robert Palmer\",\n tracks: [ ]\n },\n 5439: {\n album: \"ABBA Gold\"\n }\n};\n// Keep a copy of the collection for tests\nvar collectionCopy = JSON.parse(JSON.stringify(collection));\n\n// Only change code below this line\nfunction updateRecords(id, prop, value) {\n if(value === \"\") delete collection[id][prop];\n else if(prop === \"tracks\") {\n collection[id][prop] = collection[id][prop] || [];\n collection[id][prop].push(value);\n } else {\n collection[id][prop] = value;\n }\n \n return collection;\n}"
+ "var collection = {\n 2548: {\n album: \"Slippery When Wet\",\n artist: \"Bon Jovi\",\n tracks: [ \n \"Let It Rock\", \n \"You Give Love a Bad Name\" \n ]\n },\n 2468: {\n album: \"1999\",\n artist: \"Prince\",\n tracks: [ \n \"1999\", \n \"Little Red Corvette\" \n ]\n },\n 1245: {\n artist: \"Robert Palmer\",\n tracks: [ ]\n },\n 5439: {\n album: \"ABBA Gold\"\n }\n};\n// Keep a copy of the collection for tests\nvar collectionCopy = JSON.parse(JSON.stringify(collection));\n\n// 请把你的代码写在这条注释以下\nfunction updateRecords(id, prop, value) {\n if(value === \"\") delete collection[id][prop];\n else if(prop === \"tracks\") {\n collection[id][prop] = collection[id][prop] || [];\n collection[id][prop].push(value);\n } else {\n collection[id][prop] = value;\n }\n \n return collection;\n}"
],
"tests": [
{
- "text": "After updateRecords(5439, \"artist\", \"ABBA\")
, artist
should be \"ABBA\"
",
- "testString": "collection = collectionCopy; assert(updateRecords(5439, \"artist\", \"ABBA\")[5439][\"artist\"] === \"ABBA\", 'After updateRecords(5439, \"artist\", \"ABBA\")
, artist
should be \"ABBA\"
');"
+ "text": "执行updateRecords(5439, \"artist\", \"ABBA\")
,后artist
属性值应该是\"ABBA\"
",
+ "testString": "collection = collectionCopy; assert(updateRecords(5439, \"artist\", \"ABBA\")[5439][\"artist\"] === \"ABBA\", '执行updateRecords(5439, \"artist\", \"ABBA\")
,后artist
属性值应该是\"ABBA\"
');"
},
{
- "text": "After updateRecords(5439, \"tracks\", \"Take a Chance on Me\")
, tracks
should have \"Take a Chance on Me\"
as the last element.",
- "testString": "assert(updateRecords(5439, \"tracks\", \"Take a Chance on Me\")[5439][\"tracks\"].pop() === \"Take a Chance on Me\", 'After updateRecords(5439, \"tracks\", \"Take a Chance on Me\")
, tracks
should have \"Take a Chance on Me\"
as the last element.');"
+ "text": "执行updateRecords(5439, \"tracks\", \"Take a Chance on Me\")
,后tracks
最后的元素应该是\"Take a Chance on Me\"
",
+ "testString": "assert(updateRecords(5439, \"tracks\", \"Take a Chance on Me\")[5439][\"tracks\"].pop() === \"Take a Chance on Me\", '执行updateRecords(5439, \"tracks\", \"Take a Chance on Me\")
,后tracks
最后的元素应该是\"Take a Chance on Me\"
');"
},
{
- "text": "After updateRecords(2548, \"artist\", \"\")
, artist
should not be set",
- "testString": "updateRecords(2548, \"artist\", \"\"); assert(!collection[2548].hasOwnProperty(\"artist\"), 'After updateRecords(2548, \"artist\", \"\")
, artist
should not be set');"
+ "text": "执行updateRecords(2548, \"artist\", \"\")
,后artist
should not be set",
+ "testString": "updateRecords(2548, \"artist\", \"\"); assert(!collection[2548].hasOwnProperty(\"artist\"), '执行updateRecords(2548, \"artist\", \"\")
,后artist
should not be set');"
},
{
- "text": "After updateRecords(1245, \"tracks\", \"Addicted to Love\")
, tracks
should have \"Addicted to Love\"
as the last element.",
- "testString": "assert(updateRecords(1245, \"tracks\", \"Addicted to Love\")[1245][\"tracks\"].pop() === \"Addicted to Love\", 'After updateRecords(1245, \"tracks\", \"Addicted to Love\")
, tracks
should have \"Addicted to Love\"
as the last element.');"
+ "text": "执行updateRecords(1245, \"tracks\", \"Addicted to Love\")
,后tracks
最后的元素应该是\"Addicted to Love\"
",
+ "testString": "assert(updateRecords(1245, \"tracks\", \"Addicted to Love\")[1245][\"tracks\"].pop() === \"Addicted to Love\", '执行updateRecords(1245, \"tracks\", \"Addicted to Love\")
,后tracks
最后的元素应该是\"Addicted to Love\"
');"
},
{
- "text": "After updateRecords(2468, \"tracks\", \"Free\")
, tracks
should have \"1999\"
as the first element.",
- "testString": "assert(updateRecords(2468, \"tracks\", \"Free\")[2468][\"tracks\"][0] === \"1999\", 'After updateRecords(2468, \"tracks\", \"Free\")
, tracks
should have \"1999\"
as the first element.');"
+ "text": "执行updateRecords(2468, \"tracks\", \"Free\")
,后tracks
第一个元素应该是\"1999\"
",
+ "testString": "assert(updateRecords(2468, \"tracks\", \"Free\")[2468][\"tracks\"][0] === \"1999\", '执行updateRecords(2468, \"tracks\", \"Free\")
,后tracks
第一个元素应该是\"1999\"
');"
},
{
- "text": "After updateRecords(2548, \"tracks\", \"\")
, tracks
should not be set",
- "testString": "updateRecords(2548, \"tracks\", \"\"); assert(!collection[2548].hasOwnProperty(\"tracks\"), 'After updateRecords(2548, \"tracks\", \"\")
, tracks
should not be set');"
+ "text": "执行updateRecords(2548, \"tracks\", \"\")
,后tracks
应该被创建",
+ "testString": "updateRecords(2548, \"tracks\", \"\"); assert(!collection[2548].hasOwnProperty(\"tracks\"), '执行updateRecords(2548, \"tracks\", \"\")
,后tracks
应该被创建');"
},
{
- "text": "After updateRecords(1245, \"album\", \"Riptide\")
, album
should be \"Riptide\"
",
- "testString": "assert(updateRecords(1245, \"album\", \"Riptide\")[1245][\"album\"] === \"Riptide\", 'After updateRecords(1245, \"album\", \"Riptide\")
, album
should be \"Riptide\"
');"
+ "text": "执行updateRecords(1245, \"album\", \"Riptide\")
,后album
应该是\"Riptide\"
",
+ "testString": "assert(updateRecords(1245, \"album\", \"Riptide\")[1245][\"album\"] === \"Riptide\", 'After updateRecords(1245, \"album\", \"Riptide\")
,后album
应该是\"Riptide\"
');"
}
],
"challengeType": 1,
@@ -5642,7 +5639,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var collection = {",
" \"2548\": {",
" \"album\": \"Slippery When Wet\",",
@@ -5668,17 +5665,17 @@
" \"album\": \"ABBA Gold\"",
" }",
"};",
- "// Keep a copy of the collection for tests",
+ "// 复制 collection 以便测试",
"var collectionCopy = JSON.parse(JSON.stringify(collection));",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"function updateRecords(id, prop, value) {",
" ",
" ",
" return collection;",
"}",
"",
- "// Alter values below to test your code",
+ "// 你可以修改这一行来测试你的代码",
"updateRecords(5439, \"artist\", \"ABBA\");",
""
],
@@ -5693,24 +5690,24 @@
"id": "cf1111c1c11feddfaeb1bdef",
"title": "Iterate with JavaScript While Loops",
"description": [
- "You can run the same code multiple times by using a loop.",
- "The first type of loop we will learn is called a \"while
\" loop because it runs \"while\" a specified condition is true and stops once that condition is no longer true.",
+ "你可以使用循环多次执行相同的代码。",
+ "我们将学习的第一种类型的循环称为 \"while
\" 循环,因为它规定,当 \"while\" 条件为真,循环才会执行,反之不执行。",
"var ourArray = [];
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
",
- "Let's try getting a while loop to work by pushing values to an array.",
+ "让我们通过 while 循环将值添加到数组中。",
"
",
- "Push the numbers 0 through 4 to myArray
using a while
loop."
+ "通过一个while
循环,把从 0 到 4 的值添加到myArray
中。"
],
"solutions": [
"var myArray = [];\nvar i = 0;\nwhile(i < 5) {\n myArray.push(i);\n i++;\n}"
],
"tests": [
{
- "text": "You should be using a while
loop for this.",
- "testString": "assert(code.match(/while/g), 'You should be using a while
loop for this.');"
+ "text": "你应该使用while
循环",
+ "testString": "assert(code.match(/while/g), '你应该使用while
循环');"
},
{
- "text": "myArray
should equal [0,1,2,3,4]
.",
- "testString": "assert.deepEqual(myArray, [0,1,2,3,4], 'myArray
should equal [0,1,2,3,4]
.');"
+ "text": "myArray
应该等于[0,1,2,3,4]
.",
+ "testString": "assert.deepEqual(myArray, [0,1,2,3,4], 'myArray
应该等于[0,1,2,3,4]
.');"
}
],
"challengeType": 1,
@@ -5720,10 +5717,10 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myArray = [];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5738,30 +5735,30 @@
"id": "cf1111c1c11feddfaeb5bdef",
"title": "Iterate with JavaScript For Loops",
"description": [
- "You can run the same code multiple times by using a loop.",
- "The most common type of JavaScript loop is called a \"for loop
\" because it runs \"for\" a specific number of times.",
- "For loops are declared with three optional expressions separated by semicolons:",
- "for ([initialization]; [condition]; [final-expression])
",
- "The initialization
statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable.",
- "The condition
statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to true
. When condition
is false
at the start of the iteration, the loop will stop executing. This means if condition
starts as false
, your loop will never execute.",
- "The final-expression
is executed at the end of each loop iteration, prior to the next condition
check and is usually used to increment or decrement your loop counter.",
- "In the following example we initialize with i = 0
and iterate while our condition i < 5
is true. We'll increment i
by 1
in each loop iteration with i++
as our final-expression
.",
+ "你可以使用循环多次执行相同的代码。",
+ "JavaScript 中最常见的循环就是“for循环
”。",
+ "for循环中的三个表达式用分号隔开:",
+ "for ([初始化]; [条件判断]; [计数器])
",
+ "初始化
语句只会在执行循环开始之前执行一次。它通常用于定义和设置你的循环变量。",
+ "条件判断
语句会在每一轮循环的开始执行,只要条件判断为true
就会继续执行循环。当条件为false
的时候,循环将停止执行。这意味着,如果条件在一开始就为false
,这个循环将不会执行。",
+ "计数器
是在每一轮循环结束时执行,通常用于递增或递减。",
+ "在下面的例子中,先初始化i = 0
,条件i < 5
为真,进入第一次循环,执行大括号里的代码,第一次循环结束。递增i
的值,条件判断,就这样依次执行下去,直到条件判断为假,整个循环结束。",
"var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
",
- "ourArray
will now contain [0,1,2,3,4]
.",
+ "最终ourArray
的值为[0,1,2,3,4]
.",
"
",
- "Use a for
loop to work to push the values 1 through 5 onto myArray
."
+ "使用for
循环把从 1 到 5 添加进myArray
中。"
],
"solutions": [
"var ourArray = [];\nfor (var i = 0; i < 5; i++) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 1; i < 6; i++) {\n myArray.push(i);\n}"
],
"tests": [
{
- "text": "You should be using a for
loop for this.",
- "testString": "assert(code.match(/for\\s*\\(/g).length > 1, 'You should be using a for
loop for this.');"
+ "text": "你应该使用for
循环",
+ "testString": "assert(code.match(/for\\s*\\(/g).length > 1, '你应该使用for
循环');"
},
{
- "text": "myArray
should equal [1,2,3,4,5]
.",
- "testString": "assert.deepEqual(myArray, [1,2,3,4,5], 'myArray
should equal [1,2,3,4,5]
.');"
+ "text": "myArray
应该等于[1,2,3,4,5]
",
+ "testString": "assert.deepEqual(myArray, [1,2,3,4,5], 'myArray
应该等于[1,2,3,4,5]
');"
}
],
"challengeType": 1,
@@ -5771,17 +5768,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [];",
"",
"for (var i = 0; i < 5; i++) {",
" ourArray.push(i);",
"}",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5796,25 +5793,26 @@
"id": "56104e9e514f539506016a5c",
"title": "Iterate Odd Numbers With a For Loop",
"description": [
- "For loops don't have to iterate one at a time. By changing our final-expression
, we can count by even numbers.",
- "We'll start at i = 0
and loop while i < 10
. We'll increment i
by 2 each loop with i += 2
.",
+ "for循环可以按照我们指定的顺序来迭代,通过更改我们的计数器
,我们可以按照偶数顺序来迭代。",
+ "初始化i = 0
,当i < 10
的时候继续循环。",
+ "i += 2
让i
每次循环之后增加2。",
"var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
",
- "ourArray
will now contain [0,2,4,6,8]
.",
- "Let's change our initialization
so we can count by odd numbers.",
+ "循环结束后,ourArray
的值为[0,2,4,6,8]
。",
+ "改变计数器
,这样我们可以用奇数来数。",
"
",
- "Push the odd numbers from 1 through 9 to myArray
using a for
loop."
+ "写一个for
循环,把从 1 到 9 的奇数添加到myArray
。"
],
"solutions": [
"var ourArray = [];\nfor (var i = 0; i < 10; i += 2) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 1; i < 10; i += 2) {\n myArray.push(i);\n}"
],
"tests": [
{
- "text": "You should be using a for
loop for this.",
- "testString": "assert(code.match(/for\\s*\\(/g).length > 1, 'You should be using a for
loop for this.');"
+ "text": "你应该使用for
循环",
+ "testString": "assert(code.match(/for\\s*\\(/g).length > 1, '你应该使用for
循环');"
},
{
- "text": "myArray
should equal [1,3,5,7,9]
.",
- "testString": "assert.deepEqual(myArray, [1,3,5,7,9], 'myArray
should equal [1,3,5,7,9]
.');"
+ "text": "myArray
应该等于[1,3,5,7,9]
.",
+ "testString": "assert.deepEqual(myArray, [1,3,5,7,9], 'myArray
应该等于[1,3,5,7,9]
.');"
}
],
"challengeType": 1,
@@ -5824,17 +5822,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [];",
"",
"for (var i = 0; i < 10; i += 2) {",
" ourArray.push(i);",
"}",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5849,30 +5847,30 @@
"id": "56105e7b514f539506016a5e",
"title": "Count Backwards With a For Loop",
"description": [
- "A for loop can also count backwards, so long as we can define the right conditions.",
- "In order to count backwards by twos, we'll need to change our initialization
, condition
, and final-expression
.",
- "We'll start at i = 10
and loop while i > 0
. We'll decrement i
by 2 each loop with i -= 2
.",
+ "for循环也可以逆向迭代,只要我们定义好合适的条件。",
+ "为了能够从后往前两两倒数,我们需要改变我们的初始化
,条件判断
和计数器
。",
+ "我们让i = 10
,并且当i > 0
的时候才继续循环。我们使用i -= 2
来让i
每次循环递减 2。",
"var ourArray = [];
for (var i=10; i > 0; i-=2) {
ourArray.push(i);
}
",
- "ourArray
will now contain [10,8,6,4,2]
.",
- "Let's change our initialization
and final-expression
so we can count backward by twos by odd numbers.",
+ "循环结束后,ourArray
的值为[10,8,6,4,2]
。",
+ "让我们改变初始化
和计数器
,这样我们就可以按照奇数从后往前两两倒着数。",
"
",
- "Push the odd numbers from 9 through 1 to myArray
using a for
loop."
+ "使用一个for
循环,把 9 到 1 的奇数添加进myArray
。"
],
"solutions": [
"var ourArray = [];\nfor (var i = 10; i > 0; i -= 2) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 9; i > 0; i -= 2) {\n myArray.push(i);\n}"
],
"tests": [
{
- "text": "You should be using a for
loop for this.",
- "testString": "assert(code.match(/for\\s*\\(/g).length > 1, 'You should be using a for
loop for this.');"
+ "text": "你应该使用for
循环",
+ "testString": "assert(code.match(/for\\s*\\(/g).length > 1, '你应该使用for
循环');"
},
{
- "text": "You should be using the array method push
.",
- "testString": "assert(code.match(/myArray.push/), 'You should be using the array method push
.');"
+ "text": "你应该使用数组方法push
.",
+ "testString": "assert(code.match(/myArray.push/), '你应该使用数组方法push
.');"
},
{
- "text": "myArray
should equal [9,7,5,3,1]
.",
- "testString": "assert.deepEqual(myArray, [9,7,5,3,1], 'myArray
should equal [9,7,5,3,1]
.');"
+ "text": "myArray
应该等于[9,7,5,3,1]
.",
+ "testString": "assert.deepEqual(myArray, [9,7,5,3,1], 'myArray
应该等于[9,7,5,3,1]
.');"
}
],
"challengeType": 1,
@@ -5882,17 +5880,17 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArray = [];",
"",
"for (var i = 10; i > 0; i -= 2) {",
" ourArray.push(i);",
"}",
"",
- "// Setup",
+ "// 初始化变量",
"var myArray = [];",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5907,11 +5905,11 @@
"id": "5675e877dbd60be8ad28edc6",
"title": "Iterate Through an Array with a For Loop",
"description": [
- "A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a for
loop. This code will output each element of the array arr
to the console:",
+ "迭代输出一个数组的每个元素是 JavaScript 中的常见需求,for
循环可以做到这一点。下面的代码将输出数组 arr
的每个元素到控制台:",
"var arr = [10,9,8,7,6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
",
- "Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is i < arr.length
, which stops when i
is at length - 1.",
+ "记住数组的索引从零开始的,这意味着数组的最后一个元素的下标是:数组的长度 -1。我们这个循环的 条件是i < arr.length
,当i
的值为 长度 -1 的时候循环就停止了。",
"
",
- "Declare and initialize a variable total
to 0
. Use a for
loop to add the value of each element of the myArr
array to total
."
+ "声明并初始化一个变量total
为0
。使用for
循环,使得total
的值为myArr
的数组中的每个元素的值的总和。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5919,20 +5917,20 @@
],
"tests": [
{
- "text": "total
should be declared and initialized to 0",
- "testString": "assert(code.match(/var.*?total\\s*=\\s*0.*?;/), 'total
should be declared and initialized to 0');"
+ "text": "total
应该被声明, 并且初始化值为 0",
+ "testString": "assert(code.match(/var.*?total\\s*=\\s*0.*?;/), 'total
应该被声明, 并且初始化值为 0');"
},
{
- "text": "total
should equal 20",
- "testString": "assert(total === 20, 'total
should equal 20');"
+ "text": "total
应该等于 20",
+ "testString": "assert(total === 20, 'total
应该等于 20');"
},
{
- "text": "You should use a for
loop to iterate through myArr
",
- "testString": "assert(code.match(/for\\s*\\(/g).length > 1 && code.match(/myArr\\s*\\[/), 'You should use a for
loop to iterate through myArr
');"
+ "text": "你应该使用for
循环在myArr
中遍历",
+ "testString": "assert(code.match(/for\\s*\\(/g).length > 1 && code.match(/myArr\\s*\\[/), '你应该使用for
循环在myArr
中遍历');"
},
{
- "text": "Do not set total
to 20 directly",
- "testString": "assert(!code.match(/total[\\s\\+\\-]*=\\s*(\\d(?!\\s*[;,])|[1-9])/g), 'Do not set total
to 20 directly');"
+ "text": "不能直接把total
设置成 20",
+ "testString": "assert(!code.match(/total[\\s\\+\\-]*=\\s*(\\d(?!\\s*[;,])|[1-9])/g), '不能直接把total
设置成 20');"
}
],
"challengeType": 1,
@@ -5942,7 +5940,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"var ourArr = [ 9, 10, 11, 12];",
"var ourTotal = 0;",
"",
@@ -5950,10 +5948,10 @@
" ourTotal += ourArr[i];",
"}",
"",
- "// Setup",
+ "// 初始化变量",
"var myArr = [ 2, 3, 4, 5, 6];",
"",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
""
],
@@ -5968,11 +5966,11 @@
"id": "56533eb9ac21ba0edf2244e1",
"title": "Nesting For Loops",
"description": [
- "If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:",
+ "如果你有一个二维数组,可以使用相同的逻辑,先遍历外面的数组,再遍历里面的子数组。下面是一个例子:",
"var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
",
- "This outputs each sub-element in arr
one at a time. Note that for the inner loop, we are checking the .length
of arr[i]
, since arr[i]
is itself an array.",
+ "一次输出arr
中的每个子元素。提示,对于内部循环,我们可以通过arr[i]
的.length
来获得子数组的长度,因为arr[i]
的本身就是一个数组。",
"
",
- "Modify function multiplyAll
so that it multiplies the product
variable by each number in the sub-arrays of arr
"
+ "修改函数multiplyAll
,获得arr
内部数组的每个数字相乘的结果product
。"
],
"releasedOn": "January 1, 2016",
"solutions": [
@@ -5980,16 +5978,16 @@
],
"tests": [
{
- "text": "multiplyAll([[1],[2],[3]])
should return 6
",
- "testString": "assert(multiplyAll([[1],[2],[3]]) === 6, 'multiplyAll([[1],[2],[3]])
should return 6
');"
+ "text": "multiplyAll([[1],[2],[3]])
应该返回 6
",
+ "testString": "assert(multiplyAll([[1],[2],[3]]) === 6, 'multiplyAll([[1],[2],[3]])
应该返回 6
');"
},
{
- "text": "multiplyAll([[1,2],[3,4],[5,6,7]])
should return 5040
",
- "testString": "assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, 'multiplyAll([[1,2],[3,4],[5,6,7]])
should return 5040
');"
+ "text": "multiplyAll([[1,2],[3,4],[5,6,7]])
应该返回 5040
",
+ "testString": "assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, 'multiplyAll([[1,2],[3,4],[5,6,7]])
应该返回 5040
');"
},
{
- "text": "multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])
should return 54
",
- "testString": "assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, 'multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])
should return 54
');"
+ "text": "multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])
应该返回 54
",
+ "testString": "assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, 'multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])
应该返回 54
');"
}
],
"challengeType": 1,
@@ -6001,13 +5999,13 @@
"contents": [
"function multiplyAll(arr) {",
" var product = 1;",
- " // Only change code below this line",
+ " // 请把你的代码写在这条注释以下",
" ",
- " // Only change code above this line",
+ " // 请把你的代码写在这条注释以上",
" return product;",
"}",
"",
- "// Modify values below to test your code",
+ "// 你可以修改这一行来测试你的代码",
"multiplyAll([[1,2],[3,4],[5,6,7]]);",
""
],
@@ -6020,36 +6018,36 @@
"id": "5a2efd662fb457916e1fe604",
"title": "Iterate with JavaScript Do...While Loops",
"description": [
- "You can run the same code multiple times by using a loop.",
- "The next type of loop you will learn is called a \"do...while
\" loop because it first will \"do
\" one pass of the code inside the loop no matter what, and then it runs \"while
\" a specified condition is true and stops once that condition is no longer true. Let's look at an example.",
+ "你可以使用循环来多次执行相同的代码",
+ "你学习的下一个循环是 \"do...while
\" 循环,因为它首先无论如何先将 \"do
\" 内部的代码执行一次,然后它执行 \"while
\" 表达式,指定条件为真则继续执行,直到条件为假时停止执行。我们来看一个例子。",
"var ourArray = [];
var i = 0;
do {
ourArray.push(i);
i++;
} while (i < 5);
",
- "This behaves just as you would expect with any other type of loop, and the resulting array will look like [0, 1, 2, 3, 4]
. However, what makes the do...while
different from other loops is how it behaves when the condition fails on the first check. Let's see this in action.",
- "Here is a regular while loop that will run the code in the loop as long as i < 5
.",
+ "这看起来和其他循环语句差不多,返回的结果是[0, 1, 2, 3, 4]
,do...while
与其他循环不同点在于,初始条件为假时的表现,让我们通过实际的例子来看看。",
+ "这是一个普通的 while 循环,只要i < 5
,它就会在循环中运行代码。",
"var ourArray = [];
var i = 5;
while (i < 5) {
ourArray.push(i);
i++;
}
",
- "Notice that we initialize the value of i
to be 5. When we execute the next line, we notice that i
is not less than 5. So we do not execute the code inside the loop. The result is that ourArray
will end up with nothing added to it, so it will still look like this []
when all the code in the example above finishes running.",
- "Now, take a look at a do...while
loop.",
+ "注意,我们首先将i
的值初始化为 5。执行下一行时,注意到i
不小于 5,循环内的代码将不会执行。所以ourArray
最终没有添加任何内容,因此示例中的所有代码执行完时,ourArray
仍然是[]
。",
+ "现在,看一下do...while
循环。",
"var ourArray = [];
var i = 5;
do {
ourArray.push(i);
i++;
} while (i < 5);
",
- "In this case, we initialize the value of i
as 5, just like we did with the while loop. When we get to the next line, there is no check for the value of i
, so we go to the code inside the curly braces and execute it. We will add one element to the array and increment i
before we get to the condition check. Then, when we get to checking if i < 5
see that i
is now 6, which fails the conditional check. So we exit the loop and are done. At the end of the above example, the value of ourArray
is [5]
.",
- "Essentially, a do...while
loop ensures that the code inside the loop will run at least once.",
- "Let's try getting a do...while
loop to work by pushing values to an array.",
+ "在这里,和使用 while 循环时一样,我们将i
的值初始化为 5。执行下一行时,没有检查i
的值,直接执行花括号内的代码。数组会添加一个元素,并在进行条件检查之前递增i
。然后,在条件检查时因为i
等于 6 不符合条件i < 5
,所以退出循环。最终ourArray
的值是[5]
。",
+ "本质上,do...while
循环确保循环内的代码至少运行一次。",
+ "让我们通过do...while
循环将值添加到数组中。",
"
",
- "Change the while
loop in the code to a do...while
loop so that the loop will push the number 10 to myArray
, and i
will be equal to 11
when your code finishes running."
+ "将代码中的while
循环更改为do...while
循环,实现数字 10 添加到myArray
中,代码执行完时,i
等于11
。"
],
"solutions": [
"var myArray = [];\nvar i = 10;\ndo {\n myArray.push(i);\n i++;\n} while (i < 5)"
],
"tests": [
{
- "text": "You should be using a do...while
loop for this.",
- "testString": "assert(code.match(/do/g), 'You should be using a do...while
loop for this.');"
+ "text": "你应该使用do...while
循环",
+ "testString": "assert(code.match(/do/g), '你应该使用do...while
循环');"
},
{
- "text": "myArray
should equal [10]
.",
- "testString": "assert.deepEqual(myArray, [10], 'myArray
should equal [10]
.');"
+ "text": "myArray
应该等于[10]
.",
+ "testString": "assert.deepEqual(myArray, [10], 'myArray
应该等于[10]
.');"
},
{
- "text": "i
should equal 11
",
- "testString": "assert.deepEqual(i, 11, 'i
should equal 11
');"
+ "text": "i
应该等于11
",
+ "testString": "assert.deepEqual(i, 11, 'i
应该等于11
');"
}
],
"challengeType": 1,
@@ -6059,11 +6057,11 @@
"ext": "js",
"name": "index",
"contents": [
- "// Setup",
+ "// 初始化变量",
"var myArray = [];",
"var i = 10;",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
"while (i < 5) {",
" myArray.push(i);",
@@ -6082,12 +6080,12 @@
"id": "5688e62ea601b2482ff8422b",
"title": "Profile Lookup",
"description": [
- "We have an array of objects representing different people in our contacts lists.",
- "A lookUpProfile
function that takes name
and a property (prop
) as arguments has been pre-written for you.",
- "The function should check if name
is an actual contact's firstName
and the given property (prop
) is a property of that contact.",
- "If both are true, then return the \"value\" of that property.",
- "If name
does not correspond to any contacts then return \"No such contact\"
",
- "If prop
does not correspond to any valid properties of a contact found to match name
then return \"No such property\"
"
+ "我们有一个对象数组,里面存储着通讯录。",
+ "函数lookUp
有两个预定义参数:firstName
值和prop
属性 。",
+ "函数将会检查通讯录中是否存在一个与传入的firstName
相同的联系人。如果存在,那么还需要检查对应的联系人中是否存在prop
属性。",
+ "如果它们都存在,函数返回prop
属性对应的值。",
+ "如果firstName
值不存在,返回\"No such contact\"
。",
+ "如果prop
属性不存在,返回\"No such property\"
。"
],
"releasedOn": "January 8, 2016",
"solutions": [
@@ -6095,28 +6093,28 @@
],
"tests": [
{
- "text": "\"Kristian\", \"lastName\"
should return \"Vos\"
",
- "testString": "assert(lookUpProfile('Kristian','lastName') === \"Vos\", '\"Kristian\", \"lastName\"
should return \"Vos\"
');"
+ "text": "\"Kristian\", \"lastName\"
应该返回 \"Vos\"
",
+ "testString": "assert(lookUpProfile('Kristian','lastName') === \"Vos\", '\"Kristian\", \"lastName\"
应该返回 \"Vos\"
');"
},
{
- "text": "\"Sherlock\", \"likes\"
should return [\"Intriguing Cases\", \"Violin\"]
",
- "testString": "assert.deepEqual(lookUpProfile(\"Sherlock\", \"likes\"), [\"Intriguing Cases\", \"Violin\"], '\"Sherlock\", \"likes\"
should return [\"Intriguing Cases\", \"Violin\"]
');"
+ "text": "\"Sherlock\", \"likes\"
应该返回 [\"Intriguing Cases\", \"Violin\"]
",
+ "testString": "assert.deepEqual(lookUpProfile(\"Sherlock\", \"likes\"), [\"Intriguing Cases\", \"Violin\"], '\"Sherlock\", \"likes\"
应该返回 [\"Intriguing Cases\", \"Violin\"]
');"
},
{
- "text": "\"Harry\",\"likes\"
should return an array",
- "testString": "assert(typeof lookUpProfile(\"Harry\", \"likes\") === \"object\", '\"Harry\",\"likes\"
should return an array');"
+ "text": "\"Harry\",\"likes\"
应该返回 an array",
+ "testString": "assert(typeof lookUpProfile(\"Harry\", \"likes\") === \"object\", '\"Harry\",\"likes\"
应该返回 an array');"
},
{
- "text": "\"Bob\", \"number\"
should return \"No such contact\"",
- "testString": "assert(lookUpProfile(\"Bob\", \"number\") === \"No such contact\", '\"Bob\", \"number\"
should return \"No such contact\"');"
+ "text": "\"Bob\", \"number\"
应该返回 \"No such contact\"",
+ "testString": "assert(lookUpProfile(\"Bob\", \"number\") === \"No such contact\", '\"Bob\", \"number\"
应该返回 \"No such contact\"');"
},
{
- "text": "\"Bob\", \"potato\"
should return \"No such contact\"",
- "testString": "assert(lookUpProfile(\"Bob\", \"potato\") === \"No such contact\", '\"Bob\", \"potato\"
should return \"No such contact\"');"
+ "text": "\"Bob\", \"potato\"
应该返回 \"No such contact\"",
+ "testString": "assert(lookUpProfile(\"Bob\", \"potato\") === \"No such contact\", '\"Bob\", \"potato\"
应该返回 \"No such contact\"');"
},
{
- "text": "\"Akira\", \"address\"
should return \"No such property\"",
- "testString": "assert(lookUpProfile(\"Akira\", \"address\") === \"No such property\", '\"Akira\", \"address\"
should return \"No such property\"');"
+ "text": "\"Akira\", \"address\"
应该返回 \"No such property\"",
+ "testString": "assert(lookUpProfile(\"Akira\", \"address\") === \"No such property\", '\"Akira\", \"address\"
应该返回 \"No such property\"');"
}
],
"challengeType": 1,
@@ -6126,7 +6124,7 @@
"ext": "js",
"name": "index",
"contents": [
- "//Setup",
+ "// 初始化变量",
"var contacts = [",
" {",
" \"firstName\": \"Akira\",",
@@ -6156,12 +6154,12 @@
"",
"",
"function lookUpProfile(name, prop){",
- "// Only change code below this line",
+ "// 请把你的代码写在这条注释以下",
"",
- "// Only change code above this line",
+ "// 请把你的代码写在这条注释以上",
"}",
"",
- "// Change these values to test your function",
+ "// 你可以修改这一行来测试你的代码",
"lookUpProfile(\"Akira\", \"likes\");"
],
"head": [],
@@ -6173,27 +6171,27 @@
"id": "cf1111c1c11feddfaeb9bdef",
"title": "Generate Random Fractions with JavaScript",
"description": [
- "Random numbers are useful for creating random behavior.",
- "JavaScript has a Math.random()
function that generates a random decimal number between 0
(inclusive) and not quite up to 1
(exclusive). Thus Math.random()
can return a 0
but never quite return a 1
",
- "Note
Like Storing Values with the Equal Operator, all function calls will be resolved before the return
executes, so we can return
the value of the Math.random()
function.",
+ "随机数非常适合用来创建随机行为。",
+ "Math.random()
用来生成一个在0
(包括 0)到1
不包括 1)之间的随机小数,因此Math.random()
可能返回 0 但绝不会返回 1。",
+ "提示
这一节讲过Storing Values with the Equal Operator,所有函数调用将在return
执行之前解析,因此我们可以返回Math.random()
函数的值。",
"
",
- "Change randomFraction
to return a random number instead of returning 0
."
+ "更改randomFraction
使其返回一个随机数而不是0
。"
],
"solutions": [
"function randomFraction() {\n return Math.random();\n}"
],
"tests": [
{
- "text": "randomFraction
should return a random number.",
- "testString": "assert(typeof randomFraction() === \"number\", 'randomFraction
should return a random number.');"
+ "text": "randomFraction
应该返回一个随机数",
+ "testString": "assert(typeof randomFraction() === \"number\", 'randomFraction
应该返回一个随机数');"
},
{
- "text": "The number returned by randomFraction
should be a decimal.",
- "testString": "assert((randomFraction()+''). match(/\\./g), 'The number returned by randomFraction
should be a decimal.');"
+ "text": "randomFraction
应该返回一个小数",
+ "testString": "assert((randomFraction()+''). match(/\\./g), 'randomFraction
应该返回一个小数');"
},
{
- "text": "You should be using Math.random
to generate the random decimal number.",
- "testString": "assert(code.match(/Math\\.random/g).length >= 0, 'You should be using Math.random
to generate the random decimal number.');"
+ "text": "需要使用Math.random
生成随机的小数",
+ "testString": "assert(code.match(/Math\\.random/g).length >= 0, '需要使用Math.random
生成随机的小数');"
}
],
"challengeType": 1,
@@ -6205,11 +6203,11 @@
"contents": [
"function randomFraction() {",
"",
- " // Only change code below this line.",
+ " // 请把你的代码写在这条注释以下",
"",
" return 0;",
"",
- " // Only change code above this line.",
+ " // 请把你的代码写在这条注释以上.",
"}"
],
"head": [],
@@ -6223,34 +6221,34 @@
"id": "cf1111c1c12feddfaeb1bdef",
"title": "Generate Random Whole Numbers with JavaScript",
"description": [
- "It's great that we can generate random decimal numbers, but it's even more useful if we use it to generate random whole numbers.",
- "- Use
Math.random()
to generate a random decimal. - Multiply that random decimal by
20
. - Use another function,
Math.floor()
to round the number down to its nearest whole number.
",
- "Remember that Math.random()
can never quite return a 1
and, because we're rounding down, it's impossible to actually get 20
. This technique will give us a whole number between 0
and 19
.",
- "Putting everything together, this is what our code looks like:",
+ "生成随机小数很棒,但随机数更有用的地方在于生成随机整数。",
+ "- 用
Math.random()
生成一个随机小数。 - 把这个随机小数乘以
20
。 - 用
Math.floor()
向下取整 获得它最近的整数。
",
+ "记住Math.random()
永远不会返回1
。同时因为我们是在用Math.floor()
向下取整,所以最终我们获得的结果不可能有20
。这确保了我们获得了一个在0到19之间的整数。",
+ "把操作连缀起来,代码类似于下面:",
"Math.floor(Math.random() * 20);
",
- "We are calling Math.random()
, multiplying the result by 20, then passing the value to Math.floor()
function to round the value down to the nearest whole number.",
+ "我们先调用Math.random()
,把它的结果乘以20,然后把上一步的结果传给Math.floor()
,最终通过向下取整获得最近的整数。",
"
",
- "Use this technique to generate and return a random whole number between 0
and 9
."
+ "生成一个0
到9
之间的随机整数。"
],
"solutions": [
"var randomNumberBetween0and19 = Math.floor(Math.random() * 20);\nfunction randomWholeNum() {\n return Math.floor(Math.random() * 10);\n}"
],
"tests": [
{
- "text": "The result of randomWholeNum
should be a whole number.",
- "testString": "assert(typeof randomWholeNum() === \"number\" && (function(){var r = randomWholeNum();return Math.floor(r) === r;})(), 'The result of randomWholeNum
should be a whole number.');"
+ "text": "myFunction
的结果应该是一个整数",
+ "testString": "assert(typeof randomWholeNum() === \"number\" && (function(){var r = randomWholeNum();return Math.floor(r) === r;})(), 'myFunction
的结果应该是一个整数');"
},
{
- "text": "You should be using Math.random
to generate a random number.",
- "testString": "assert(code.match(/Math.random/g).length > 1, 'You should be using Math.random
to generate a random number.');"
+ "text": "需要使用Math.random
生成随机数字",
+ "testString": "assert(code.match(/Math.random/g).length > 1, '需要使用Math.random
生成随机数字');"
},
{
- "text": "You should have multiplied the result of Math.random
by 10 to make it a number that is between zero and nine.",
- "testString": "assert(code.match(/\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\*\\s*?10[\\D]\\s*?/g) || code.match(/\\s*?10\\s*?\\*\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?/g), 'You should have multiplied the result of Math.random
by 10 to make it a number that is between zero and nine.');"
+ "text": "你应该将Math.random
的结果乘以 10 来生成 0 到 9 之间的随机数",
+ "testString": "assert(code.match(/\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\*\\s*?10[\\D]\\s*?/g) || code.match(/\\s*?10\\s*?\\*\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?/g), '你应该将Math.random
的结果乘以 10 来生成 0 到 9 之间的随机数');"
},
{
- "text": "You should use Math.floor
to remove the decimal part of the number.",
- "testString": "assert(code.match(/Math.floor/g).length > 1, 'You should use Math.floor
to remove the decimal part of the number.');"
+ "text": "你需要使用Math.floor
移除数字中的小数部分",
+ "testString": "assert(code.match(/Math.floor/g).length > 1, '你需要使用Math.floor
移除数字中的小数部分');"
}
],
"challengeType": 1,
@@ -6264,7 +6262,7 @@
"",
"function randomWholeNum() {",
"",
- " // Only change code below this line.",
+ " // 请把你的代码写在这条注释以下",
"",
" return Math.random();",
"}"
@@ -6280,32 +6278,32 @@
"id": "cf1111c1c12feddfaeb2bdef",
"title": "Generate Random Whole Numbers within a Range",
"description": [
- "Instead of generating a random number between zero and a given number like we did before, we can generate a random number that falls within a range of two specific numbers.",
- "To do this, we'll define a minimum number min
and a maximum number max
.",
- "Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:",
+ "我们之前生成的随机数是在0到某个数之间,现在我们要生成的随机数是在两个指定的数之间。",
+ "我们需要定义一个最小值和一个最大值。",
+ "下面是我们将要使用的方法,仔细看看并尝试理解这行代码到底在干嘛:",
"Math.floor(Math.random() * (max - min + 1)) + min
",
"
",
- "Create a function called randomRange
that takes a range myMin
and myMax
and returns a random number that's greater than or equal to myMin
, and is less than or equal to myMax
, inclusive."
+ "创建一个叫randomRange
的函数,参数为 myMin 和 myMax,返回一个在myMin
(包括 myMin)和myMax
(包括 myMax)之间的随机数。"
],
"solutions": [
"function randomRange(myMin, myMax) {\n return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;\n}"
],
"tests": [
{
- "text": "The lowest random number that can be generated by randomRange
should be equal to your minimum number, myMin
.",
- "testString": "assert(calcMin === 5, 'The lowest random number that can be generated by randomRange
should be equal to your minimum number, myMin
.');"
+ "text": "randomRange
返回的随机数应该大于或等于myMin
",
+ "testString": "assert(calcMin === 5, 'randomRange
返回的随机数应该大于或等于myMin
');"
},
{
- "text": "The highest random number that can be generated by randomRange
should be equal to your maximum number, myMax
.",
- "testString": "assert(calcMax === 15, 'The highest random number that can be generated by randomRange
should be equal to your maximum number, myMax
.');"
+ "text": "randomRange
返回的随机数应该小于或等于myMax
",
+ "testString": "assert(calcMax === 15, 'randomRange
返回的随机数应该小于或等于myMax
');"
},
{
- "text": "The random number generated by randomRange
should be an integer, not a decimal.",
- "testString": "assert(randomRange(0,1) % 1 === 0 , 'The random number generated by randomRange
should be an integer, not a decimal.');"
+ "text": "randomRange
应该返回一个随机整数, 而不是小数",
+ "testString": "assert(randomRange(0,1) % 1 === 0 , 'randomRange
应该返回一个随机整数, 而不是小数');"
},
{
- "text": "randomRange
should use both myMax
and myMin
, and return a random number in your range.",
- "testString": "assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), 'randomRange
should use both myMax
and myMin
, and return a random number in your range.');"
+ "text": "randomRange
应该使用myMax
和myMin
, 并且返回两者之间的随机数",
+ "testString": "assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), 'randomRange
应该使用myMax
和myMin
, 并且返回两者之间的随机数');"
}
],
"challengeType": 1,
@@ -6315,7 +6313,7 @@
"ext": "js",
"name": "index",
"contents": [
- "// Example",
+ "// 示例",
"function ourRandomRange(ourMin, ourMax) {",
"",
" return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;",
@@ -6323,15 +6321,15 @@
"",
"ourRandomRange(1, 9);",
"",
- "// Only change code below this line.",
+ "// 请把你的代码写在这条注释以下",
"",
"function randomRange(myMin, myMax) {",
"",
- " return 0; // Change this line",
+ " return 0; // 请修改这一行",
"",
"}",
"",
- "// Change these values to test your function",
+ "// 你可以修改这一行来测试你的代码",
"var myRandom = randomRange(5, 15);"
],
"head": [],
@@ -6358,33 +6356,33 @@
"id": "587d7b7e367417b2b2512b23",
"title": "Use the parseInt Function",
"description": [
- "The parseInt()
function parses a string and returns an integer. Here's an example:",
+ "parseInt()
函数解析一个字符串返回一个整数下面是一个示例:",
"var a = parseInt(\"007\");
",
- "The above function converts the string \"007\" to an integer 7. If the first character in the string can't be converted into a number, then it returns NaN
.",
+ "上面的函数把字符串 \"007\" 转换成数字 7。 如果字符串参数的第一个字符是字符串类型的,结果将不会转换成数字,而是返回NaN
.",
"
",
- "Use parseInt()
in the convertToInteger
function so it converts the input string str
into an integer, and returns it."
+ "在convertToInteger
函数中使用parseInt()
转换接受的的字符串str
为正数并返回。"
],
"solutions": [],
"tests": [
{
- "text": "convertToInteger
should use the parseInt()
function",
- "testString": "assert(/parseInt/g.test(code), 'convertToInteger
should use the parseInt()
function');"
+ "text": "convertToInteger
应该使用parseInt()
函数",
+ "testString": "assert(/parseInt/g.test(code), 'convertToInteger
应该使用parseInt()
函数');"
},
{
- "text": "convertToInteger(\"56\")
should return a number",
- "testString": "assert(typeof(convertToInteger(\"56\")) === \"number\", 'convertToInteger(\"56\")
should return a number');"
+ "text": "convertToInteger(\"56\")
应该返回一个数字",
+ "testString": "assert(typeof(convertToInteger(\"56\")) === \"number\", 'convertToInteger(\"56\")
应该返回一个数字');"
},
{
- "text": "convertToInteger(\"56\")
should return 56",
- "testString": "assert(convertToInteger(\"56\") === 56, 'convertToInteger(\"56\")
should return 56');"
+ "text": "convertToInteger(\"56\")
应该返回 56",
+ "testString": "assert(convertToInteger(\"56\") === 56, 'convertToInteger(\"56\")
应该返回 56');"
},
{
- "text": "convertToInteger(\"77\")
should return 77",
- "testString": "assert(convertToInteger(\"77\") === 77, 'convertToInteger(\"77\")
should return 77');"
+ "text": "convertToInteger(\"77\")
应该返回 77",
+ "testString": "assert(convertToInteger(\"77\") === 77, 'convertToInteger(\"77\")
应该返回 77');"
},
{
- "text": "convertToInteger(\"JamesBond\")
should return NaN",
- "testString": "assert.isNaN(convertToInteger(\"JamesBond\"), 'convertToInteger(\"JamesBond\")
should return NaN');"
+ "text": "convertToInteger(\"JamesBond\")
应该返回 NaN",
+ "testString": "assert.isNaN(convertToInteger(\"JamesBond\"), 'convertToInteger(\"JamesBond\")
应该返回 NaN');"
}
],
"challengeType": 1,
@@ -6410,36 +6408,36 @@
"id": "587d7b7e367417b2b2512b22",
"title": "Use the parseInt Function with a Radix",
"description": [
- "The parseInt()
function parses a string and returns an integer. It takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36.",
- "The function call looks like:",
+ "parseInt()
函数解析一个字符串并返回一个整数。它同时可接受第二个参数,一个介于2和36之间的整数,表示字符串的基数。",
+ "函数调用如下所示:",
"parseInt(string, radix);
",
- "And here's an example:",
+ "示例:",
"var a = parseInt(\"11\", 2);
",
- "The radix variable says that \"11\" is in the binary system, or base 2. This example converts the string \"11\" to an integer 3.",
+ "参数 2 表示 \"11\" 使用二进制数值系统。此示例将字符串 \"11\" 转换为整数 3。",
"
",
- "Use parseInt()
in the convertToInteger
function so it converts a binary number to an integer and returns it."
+ "在convertToInteger
parseInt()函数把二进制数转换成十进制并返回。"
],
"solutions": [],
"tests": [
{
- "text": "convertToInteger
should use the parseInt()
function",
- "testString": "assert(/parseInt/g.test(code), 'convertToInteger
should use the parseInt()
function');"
+ "text": "convertToInteger
中应该使用parseInt()
函数",
+ "testString": "assert(/parseInt/g.test(code), 'convertToInteger
中应该使用parseInt()
函数');"
},
{
- "text": "convertToInteger(\"10011\")
should return a number",
- "testString": "assert(typeof(convertToInteger(\"10011\")) === \"number\", 'convertToInteger(\"10011\")
should return a number');"
+ "text": "convertToInteger(\"10011\")
应该返回一个数字",
+ "testString": "assert(typeof(convertToInteger(\"10011\")) === \"number\", 'convertToInteger(\"10011\")
应该返回一个数字');"
},
{
- "text": "convertToInteger(\"10011\")
should return 19",
- "testString": "assert(convertToInteger(\"10011\") === 19, 'convertToInteger(\"10011\")
should return 19');"
+ "text": "convertToInteger(\"10011\")
应该返回 19",
+ "testString": "assert(convertToInteger(\"10011\") === 19, 'convertToInteger(\"10011\")
应该返回 19');"
},
{
- "text": "convertToInteger(\"111001\")
should return 57",
- "testString": "assert(convertToInteger(\"111001\") === 57, 'convertToInteger(\"111001\")
should return 57');"
+ "text": "convertToInteger(\"111001\")
应该返回 57",
+ "testString": "assert(convertToInteger(\"111001\") === 57, 'convertToInteger(\"111001\")
应该返回 57');"
},
{
- "text": "convertToInteger(\"JamesBond\")
should return NaN",
- "testString": "assert.isNaN(convertToInteger(\"JamesBond\"), 'convertToInteger(\"JamesBond\")
should return NaN');"
+ "text": "convertToInteger(\"JamesBond\")
应该返回 NaN",
+ "testString": "assert.isNaN(convertToInteger(\"JamesBond\"), 'convertToInteger(\"JamesBond\")
应该返回 NaN');"
}
],
"challengeType": 1,
@@ -6465,33 +6463,33 @@
"id": "587d7b7e367417b2b2512b24",
"title": "Use the Conditional (Ternary) Operator",
"description": [
- "The conditional operator, also called the ternary operator, can be used as a one line if-else expression.",
- "The syntax is:",
+ "条件运算符(也称为三元运算符)的用处就像写成一行的 if-else 表达式",
+ "语法如下所示:",
"condition ? statement-if-true : statement-if-false;
",
- "The following function uses an if-else statement to check a condition:",
+ "以下函数使用 if-else 语句来检查条件:",
"function findGreater(a, b) {
if(a > b) {
return \"a is greater\";
}
else {
return \"b is greater\";
}
}
",
- "This can be re-written using the conditional operator
:",
+ "上面的函数使用条件运算符写法如下:",
"function findGreater(a, b) {
return a > b ? \"a is greater\" : \"b is greater\";
}
",
"
",
- "Use the conditional operator
in the checkEqual
function to check if two numbers are equal or not. The function should return either true or false."
+ "在checkEqual
函数中使用条件运算符检查两个数字是否相等,函数应该返回 true 或 false"
],
"solutions": [],
"tests": [
{
- "text": "checkEqual
should use the conditional operator
",
- "testString": "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'checkEqual
should use the conditional operator
');"
+ "text": "checkEqual
应该使用条件运算符",
+ "testString": "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'checkEqual
应该使用条件运算符');"
},
{
- "text": "checkEqual(1, 2)
should return false",
- "testString": "assert(checkEqual(1, 2) === false, 'checkEqual(1, 2)
should return false');"
+ "text": "checkEqual(1, 2)
应该返回 false",
+ "testString": "assert(checkEqual(1, 2) === false, 'checkEqual(1, 2)
应该返回 false');"
},
{
- "text": "checkEqual(1, 1)
should return true",
- "testString": "assert(checkEqual(1, 1) === true, 'checkEqual(1, 1)
should return true');"
+ "text": "checkEqual(1, 1)
应该返回 true",
+ "testString": "assert(checkEqual(1, 1) === true, 'checkEqual(1, 1)
应该返回 true');"
},
{
- "text": "checkEqual(1, -1)
should return false",
- "testString": "assert(checkEqual(1, -1) === false, 'checkEqual(1, -1)
should return false');"
+ "text": "checkEqual(1, -1)
应该返回 false",
+ "testString": "assert(checkEqual(1, -1) === false, 'checkEqual(1, -1)
应该返回 false');"
}
],
"challengeType": 1,
@@ -6517,31 +6515,31 @@
"id": "587d7b7e367417b2b2512b21",
"title": "Use Multiple Conditional (Ternary) Operators",
"description": [
- "In the previous challenge, you used a single conditional operator
. You can also chain them together to check for multiple conditions.",
- "The following function uses if, else if, and else statements to check multiple conditions:",
+ "在之前的挑战中,你使用了一个条件运算符。你也可以将多个运算符串联在一起以检查多种条件。",
+ "下面的函数使用 if,else if 和 else 语句来检查多个条件:",
"function findGreaterOrEqual(a, b) {
if(a === b) {
return \"a and b are equal\";
}
else if(a > b) {
return \"a is greater\";
}
else {
return \"b is greater\";
}
}
",
- "The above function can be re-written using multiple conditional operators
:",
+ "上面的函数使用条件运算符写法如下:",
"function findGreaterOrEqual(a, b) {
return (a === b) ? \"a and b are equal\" : (a > b) ? \"a is greater\" : \"b is greater\";
}
",
"
",
- "Use multiple conditional operators
in the checkSign
function to check if a number is positive, negative or zero."
+ "在 checkSign 函数中使用多个条件运算符来检查数字是正数,负数还是零。"
],
"solutions": [],
"tests": [
{
- "text": "checkSign
should use multiple conditional operators
",
- "testString": "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'checkSign
should use multiple conditional operators
');"
+ "text": "checkSign
应该使用多个条件运算符",
+ "testString": "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'checkSign
应该使用多个条件运算符');"
},
{
- "text": "checkSign(10)
should return \"positive\". Note that capitalization matters",
- "testString": "assert(checkSign(10) === 'positive', 'checkSign(10)
should return \"positive\". Note that capitalization matters');"
+ "text": "checkSign(10)
应该返回 \"positive\" 注意,结果对大小写敏感",
+ "testString": "assert(checkSign(10) === 'positive', 'checkSign(10)
应该返回 \"positive\" 注意,结果对大小写敏感');"
},
{
- "text": "checkSign(-12)
should return \"negative\". Note that capitalization matters",
- "testString": "assert(checkSign(-12) === 'negative', 'checkSign(-12)
should return \"negative\". Note that capitalization matters');"
+ "text": "checkSign(-12)
应该返回 \"negative\" 注意,结果对大小写敏感",
+ "testString": "assert(checkSign(-12) === 'negative', 'checkSign(-12)
应该返回 \"negative\" 注意,结果对大小写敏感');"
},
{
- "text": "checkSign(0)
should return \"zero\". Note that capitalization matters",
- "testString": "assert(checkSign(0) === 'zero', 'checkSign(0)
should return \"zero\". Note that capitalization matters');"
+ "text": "checkSign(0)
应该返回 \"zero\" 注意,结果对大小写敏感",
+ "testString": "assert(checkSign(0) === 'zero', 'checkSign(0)
应该返回 \"zero\" 注意,结果对大小写敏感');"
}
],
"challengeType": 1,