feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -4,6 +4,7 @@ title: 通过索引访问数组中的数据
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cBZQbTz'
|
||||
forumTopicId: 16158
|
||||
dashedName: access-array-data-with-indexes
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -60,5 +61,26 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,z){return 'myArray = ' + JSON.stringify(y) + ', myData = ' + JSON.stringify(z);})(myArray, myData);}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [50,60,70];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [50,60,70];
|
||||
var myData = myArray[0];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用索引访问多维数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ckND4Cq'
|
||||
forumTopicId: 16159
|
||||
dashedName: access-multi-dimensional-arrays-with-indexes
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -48,5 +49,27 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " myArray: " + JSON.stringify(myArray);})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// 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];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];
|
||||
var myData = myArray[2][1];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 访问嵌套数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cLeGDtZ'
|
||||
forumTopicId: 16160
|
||||
dashedName: accessing-nested-arrays
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -53,5 +54,70 @@ assert(secondTree === 'pine');
|
||||
assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(x) {
|
||||
if(typeof x != 'undefined') {
|
||||
return "secondTree = " + x;
|
||||
}
|
||||
return "secondTree is undefined";
|
||||
})(secondTree);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myPlants = [
|
||||
{
|
||||
type: "flowers",
|
||||
list: [
|
||||
"rose",
|
||||
"tulip",
|
||||
"dandelion"
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "trees",
|
||||
list: [
|
||||
"fir",
|
||||
"pine",
|
||||
"birch"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var secondTree = ""; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myPlants = [
|
||||
{
|
||||
type: "flowers",
|
||||
list: [
|
||||
"rose",
|
||||
"tulip",
|
||||
"dandelion"
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "trees",
|
||||
list: [
|
||||
"fir",
|
||||
"pine",
|
||||
"birch"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var secondTree = myPlants[1].list[1];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 访问嵌套对象
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cRnRnfa'
|
||||
forumTopicId: 16161
|
||||
dashedName: accessing-nested-objects
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -47,5 +48,51 @@ assert(gloveBoxContents === 'maps');
|
||||
assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(x) {
|
||||
if(typeof x != 'undefined') {
|
||||
return "gloveBoxContents = " + x;
|
||||
}
|
||||
return "gloveBoxContents is undefined";
|
||||
})(gloveBoxContents);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myStorage = {
|
||||
"car": {
|
||||
"inside": {
|
||||
"glove box": "maps",
|
||||
"passenger seat": "crumbs"
|
||||
},
|
||||
"outside": {
|
||||
"trunk": "jack"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var gloveBoxContents = undefined; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStorage = {
|
||||
"car":{
|
||||
"inside":{
|
||||
"glove box":"maps",
|
||||
"passenger seat":"crumbs"
|
||||
},
|
||||
"outside":{
|
||||
"trunk":"jack"
|
||||
}
|
||||
}
|
||||
};
|
||||
var gloveBoxContents = myStorage.car.inside["glove box"];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 通过方括号访问对象属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cBvmEHP'
|
||||
forumTopicId: 16163
|
||||
dashedName: accessing-object-properties-with-bracket-notation
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -63,5 +64,38 @@ assert(drinkValue === 'water');
|
||||
assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b) { return "entreeValue = '" + a + "', drinkValue = '" + b + "'"; })(entreeValue,drinkValue);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// 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
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
"an entree": "hamburger",
|
||||
"my side": "veggies",
|
||||
"the drink": "water"
|
||||
};
|
||||
var entreeValue = testObj["an entree"];
|
||||
var drinkValue = testObj['the drink'];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 通过点符号访问对象属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cGryJs8'
|
||||
forumTopicId: 16164
|
||||
dashedName: accessing-object-properties-with-dot-notation
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -59,5 +60,39 @@ assert(shirtValue === 'jersey');
|
||||
assert(code.match(/testObj\.\w+/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// 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
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
"hat": "ballcap",
|
||||
"shirt": "jersey",
|
||||
"shoes": "cleats"
|
||||
};
|
||||
|
||||
var hatValue = testObj.hat;
|
||||
var shirtValue = testObj.shirt;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 通过变量访问对象属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cnQyKur'
|
||||
forumTopicId: 16165
|
||||
dashedName: accessing-object-properties-with-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -79,5 +80,38 @@ assert(!code.match(/player\s*=\s*"|\'\s*Montana\s*"|\'\s*;/gi));
|
||||
assert(/testObj\s*?\[\s*playerNumber\s*\]/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof player !== "undefined"){(function(v){return v;})(player);}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// 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
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
12: "Namath",
|
||||
16: "Montana",
|
||||
19: "Unitas"
|
||||
};
|
||||
var playerNumber = 16;
|
||||
var player = testObj[playerNumber];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 给对象添加新属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cQe38UD'
|
||||
forumTopicId: 301169
|
||||
dashedName: add-new-properties-to-a-javascript-object
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -38,5 +39,36 @@ assert(myDog.bark !== undefined);
|
||||
assert(!/bark[^\n]:/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return z;})(myDog);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
myDog.bark = "Woof Woof";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 加法运算
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cM2KBAG'
|
||||
forumTopicId: 16650
|
||||
dashedName: add-two-numbers-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -38,5 +39,22 @@ assert(sum === 20);
|
||||
assert(/\+/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'sum = '+z;})(sum);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var sum = 10 + 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var sum = 10 + 10;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 在 Switch 语句中添加默认选项
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c3JvVfg'
|
||||
forumTopicId: 16653
|
||||
dashedName: adding-a-default-option-in-switch-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -85,5 +86,43 @@ assert(switchOfStuff('string-to-trigger-default-case') === 'stuff');
|
||||
assert(code.match(/break/g).length > 2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function switchOfStuff(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
switchOfStuff(1);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function switchOfStuff(val) {
|
||||
var answer = "";
|
||||
|
||||
switch(val) {
|
||||
case "a":
|
||||
answer = "apple";
|
||||
break;
|
||||
case "b":
|
||||
answer = "bird";
|
||||
break;
|
||||
case "c":
|
||||
answer = "cat";
|
||||
break;
|
||||
default:
|
||||
answer = "stuff";
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 将变量附加到字符串
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cbQmZfa'
|
||||
forumTopicId: 16656
|
||||
dashedName: appending-variables-to-strings
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -28,5 +29,40 @@ assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2);
|
||||
assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
var output = [];
|
||||
if(typeof someAdjective === 'string') {
|
||||
output.push('someAdjective = "' + someAdjective + '"');
|
||||
} else {
|
||||
output.push('someAdjective is not a string');
|
||||
}
|
||||
if(typeof myStr === 'string') {
|
||||
output.push('myStr = "' + myStr + '"');
|
||||
} else {
|
||||
output.push('myStr is not a string');
|
||||
}
|
||||
return output.join('\n');
|
||||
})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Change code below this line
|
||||
|
||||
var someAdjective;
|
||||
var myStr = "Learning to code is ";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var someAdjective = "neat";
|
||||
var myStr = "Learning to code is ";
|
||||
myStr += someAdjective;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: Assigning the Value of One Variable to Another
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
forumTopicId: 418265
|
||||
dashedName: assigning-the-value-of-one-variable-to-another
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
@ -4,6 +4,7 @@ title: 用返回值来赋值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ce2pEtB'
|
||||
forumTopicId: 16658
|
||||
dashedName: assignment-with-a-returned-value
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -34,5 +35,35 @@ assert(processed === 2);
|
||||
assert(/processed\s*=\s*processArg\(\s*7\s*\)\s*;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){return "processed = " + processed})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var processed = 0;
|
||||
|
||||
function processArg(num) {
|
||||
return (num + 3) / 5;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var processed = 0;
|
||||
|
||||
function processArg(num) {
|
||||
return (num + 3) / 5;
|
||||
}
|
||||
|
||||
processed = processArg(7);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 新建 JavaScript 对象
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cWGkbtd'
|
||||
forumTopicId: 16769
|
||||
dashedName: build-javascript-objects
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -127,5 +128,32 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return z;})(myDog);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
};
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 多个 if else 语句
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/caeJgsw'
|
||||
forumTopicId: 16772
|
||||
dashedName: chaining-if-else-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -113,5 +114,36 @@ assert(testSize(20) === 'Huge');
|
||||
assert(testSize(25) === 'Huge');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testSize(num) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
return "Change Me";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
testSize(7);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testSize(num) {
|
||||
if (num < 5) {
|
||||
return "Tiny";
|
||||
} else if (num < 10) {
|
||||
return "Small";
|
||||
} else if (num < 15) {
|
||||
return "Medium";
|
||||
} else if (num < 20) {
|
||||
return "Large";
|
||||
} else {
|
||||
return "Huge";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 给代码添加注释
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
||||
forumTopicId: 16783
|
||||
dashedName: comment-your-javascript-code
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -46,5 +47,16 @@ assert(code.match(/(\/\/)...../g));
|
||||
assert(code.match(/(\/\*)([^\/]{5,})(?=\*\/)/gm));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// Fake Comment
|
||||
/* Another Comment */
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 相等运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cKyVMAL'
|
||||
forumTopicId: 16784
|
||||
dashedName: comparison-with-the-equality-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -60,5 +61,29 @@ assert(testEqual('12') === 'Equal');
|
||||
assert(code.match(/==/g) && !code.match(/===/g));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
testEqual(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testEqual(val) {
|
||||
if (val == 12) {
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 大于运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cp6GbH4'
|
||||
forumTopicId: 16786
|
||||
dashedName: comparison-with-the-greater-than-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -75,5 +76,36 @@ assert(testGreaterThan(150) === 'Over 100');
|
||||
assert(code.match(/val\s*>\s*('|")*\d+('|")*/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testGreaterThan(val) {
|
||||
if (val) { // Change this line
|
||||
return "Over 100";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Over 10";
|
||||
}
|
||||
|
||||
return "10 or Under";
|
||||
}
|
||||
|
||||
testGreaterThan(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testGreaterThan(val) {
|
||||
if (val > 100) { // Change this line
|
||||
return "Over 100";
|
||||
}
|
||||
if (val > 10) { // Change this line
|
||||
return "Over 10";
|
||||
}
|
||||
return "10 or Under";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 大于或等于运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c6KBqtV'
|
||||
forumTopicId: 16785
|
||||
dashedName: comparison-with-the-greater-than-or-equal-to-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -75,5 +76,38 @@ assert(testGreaterOrEqual(21) === '20 or Over');
|
||||
assert(code.match(/val\s*>=\s*('|")*\d+('|")*/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testGreaterOrEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "20 or Over";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "10 or Over";
|
||||
}
|
||||
|
||||
return "Less than 10";
|
||||
}
|
||||
|
||||
testGreaterOrEqual(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testGreaterOrEqual(val) {
|
||||
if (val >= 20) { // Change this line
|
||||
return "20 or Over";
|
||||
}
|
||||
|
||||
if (val >= 10) { // Change this line
|
||||
return "10 or Over";
|
||||
}
|
||||
|
||||
return "Less than 10";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 不等运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cdBm9Sr'
|
||||
forumTopicId: 16787
|
||||
dashedName: comparison-with-the-inequality-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -62,5 +63,29 @@ assert(testNotEqual('bob') === 'Not Equal');
|
||||
assert(code.match(/(?!!==)!=/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testNotEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
testNotEqual(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testNotEqual(val) {
|
||||
if (val != 99) {
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 小于运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cNVRWtB'
|
||||
forumTopicId: 16789
|
||||
dashedName: comparison-with-the-less-than-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -68,5 +69,38 @@ assert(testLessThan(99) === '55 or Over');
|
||||
assert(code.match(/val\s*<\s*('|")*\d+('|")*/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testLessThan(val) {
|
||||
if (val) { // Change this line
|
||||
return "Under 25";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Under 55";
|
||||
}
|
||||
|
||||
return "55 or Over";
|
||||
}
|
||||
|
||||
testLessThan(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testLessThan(val) {
|
||||
if (val < 25) { // Change this line
|
||||
return "Under 25";
|
||||
}
|
||||
|
||||
if (val < 55) { // Change this line
|
||||
return "Under 55";
|
||||
}
|
||||
|
||||
return "55 or Over";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 小于或等于运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cNVR7Am'
|
||||
forumTopicId: 16788
|
||||
dashedName: comparison-with-the-less-than-or-equal-to-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -74,5 +75,38 @@ assert(testLessOrEqual(55) === 'More Than 24');
|
||||
assert(code.match(/val\s*<=\s*('|")*\d+('|")*/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testLessOrEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Smaller Than or Equal to 12";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Smaller Than or Equal to 24";
|
||||
}
|
||||
|
||||
return "More Than 24";
|
||||
}
|
||||
|
||||
testLessOrEqual(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testLessOrEqual(val) {
|
||||
if (val <= 12) { // Change this line
|
||||
return "Smaller Than or Equal to 12";
|
||||
}
|
||||
|
||||
if (val <= 24) { // Change this line
|
||||
return "Smaller Than or Equal to 24";
|
||||
}
|
||||
|
||||
return "More Than 24";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 严格相等运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cy87atr'
|
||||
forumTopicId: 16790
|
||||
dashedName: comparison-with-the-strict-equality-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -51,5 +52,29 @@ assert(testStrict('7') === 'Not Equal');
|
||||
assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testStrict(val) {
|
||||
if (val) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
testStrict(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testStrict(val) {
|
||||
if (val === 7) {
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 严格不等运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cKekkUy'
|
||||
forumTopicId: 16791
|
||||
dashedName: comparison-with-the-strict-inequality-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -54,5 +55,29 @@ assert(testStrictNotEqual('bob') === 'Not Equal');
|
||||
assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testStrictNotEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
testStrictNotEqual(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testStrictNotEqual(val) {
|
||||
if (val !== 17) {
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 逻辑与运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cvbRVtr'
|
||||
forumTopicId: 16799
|
||||
dashedName: comparisons-with-the-logical-and-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -96,5 +97,34 @@ assert(testLogicalAnd(75) === 'No');
|
||||
assert(testLogicalAnd(80) === 'No');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testLogicalAnd(val) {
|
||||
// Only change code below this line
|
||||
|
||||
if (val) {
|
||||
if (val) {
|
||||
return "Yes";
|
||||
}
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return "No";
|
||||
}
|
||||
|
||||
testLogicalAnd(10);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testLogicalAnd(val) {
|
||||
if (val >= 25 && val <= 50) {
|
||||
return "Yes";
|
||||
}
|
||||
return "No";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 逻辑或运算符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cEPrGTN'
|
||||
forumTopicId: 16800
|
||||
dashedName: comparisons-with-the-logical-or-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -99,5 +100,36 @@ assert(testLogicalOr(21) === 'Outside');
|
||||
assert(testLogicalOr(25) === 'Outside');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testLogicalOr(val) {
|
||||
// Only change code below this line
|
||||
|
||||
if (val) {
|
||||
return "Outside";
|
||||
}
|
||||
|
||||
if (val) {
|
||||
return "Outside";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return "Inside";
|
||||
}
|
||||
|
||||
testLogicalOr(15);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testLogicalOr(val) {
|
||||
if (val < 10 || val > 20) {
|
||||
return "Outside";
|
||||
}
|
||||
return "Inside";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 复合赋值之 +=
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cDR6LCb'
|
||||
forumTopicId: 16661
|
||||
dashedName: compound-assignment-with-augmented-addition
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -62,5 +63,35 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 3;
|
||||
var b = 17;
|
||||
var c = 12;
|
||||
|
||||
// Only change code below this line
|
||||
a = a + 12;
|
||||
b = 9 + b;
|
||||
c = c + 7;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 3;
|
||||
var b = 17;
|
||||
var c = 12;
|
||||
|
||||
a += 12;
|
||||
b += 9;
|
||||
c += 7;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 复合赋值之 /=
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2QvKT2'
|
||||
forumTopicId: 16659
|
||||
dashedName: compound-assignment-with-augmented-division
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -56,5 +57,35 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 48;
|
||||
var b = 108;
|
||||
var c = 33;
|
||||
|
||||
// Only change code below this line
|
||||
a = a / 12;
|
||||
b = b / 4;
|
||||
c = c / 11;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 48;
|
||||
var b = 108;
|
||||
var c = 33;
|
||||
|
||||
a /= 12;
|
||||
b /= 4;
|
||||
c /= 11;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 复合赋值之 *=
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c83vrfa'
|
||||
forumTopicId: 16662
|
||||
dashedName: compound-assignment-with-augmented-multiplication
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -56,5 +57,35 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 12;
|
||||
var c = 4.6;
|
||||
|
||||
// Only change code below this line
|
||||
a = a * 5;
|
||||
b = 3 * b;
|
||||
c = c * 10;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 12;
|
||||
var c = 4.6;
|
||||
|
||||
a *= 5;
|
||||
b *= 3;
|
||||
c *= 10;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 复合赋值之 -=
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2Qv7AV'
|
||||
forumTopicId: 16660
|
||||
dashedName: compound-assignment-with-augmented-subtraction
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -54,5 +55,35 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 11;
|
||||
var b = 9;
|
||||
var c = 3;
|
||||
|
||||
// Only change code below this line
|
||||
a = a - 6;
|
||||
b = b - 15;
|
||||
c = c - 1;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 11;
|
||||
var b = 9;
|
||||
var c = 3;
|
||||
|
||||
a -= 6;
|
||||
b -= 15;
|
||||
c -= 1;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 用加号运算符连接字符串
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cNpM8AN'
|
||||
forumTopicId: 16802
|
||||
dashedName: concatenating-strings-with-plus-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -49,5 +50,28 @@ assert(/var\s+myStr/.test(code));
|
||||
assert(/myStr\s*=/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
if(typeof myStr === 'string') {
|
||||
return 'myStr = "' + myStr + '"';
|
||||
} else {
|
||||
return 'myStr is not a string';
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "This is the start. " + "This is the end.";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 用 += 运算符连接字符串
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cbQmmC4'
|
||||
forumTopicId: 16803
|
||||
dashedName: concatenating-strings-with-the-plus-equals-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -35,5 +36,31 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
if(typeof myStr === 'string') {
|
||||
return 'myStr = "' + myStr + '"';
|
||||
} else {
|
||||
return 'myStr is not a string';
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
|
||||
var myStr;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "This is the first sentence. ";
|
||||
myStr += "This is the second sentence.";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 用变量构造字符串
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cqk8rf4'
|
||||
forumTopicId: 16805
|
||||
dashedName: constructing-strings-with-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -28,5 +29,38 @@ assert(typeof myName !== 'undefined' && myName.length > 2);
|
||||
assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
var output = [];
|
||||
if(typeof myName === 'string') {
|
||||
output.push('myName = "' + myName + '"');
|
||||
} else {
|
||||
output.push('myName is not a string');
|
||||
}
|
||||
if(typeof myStr === 'string') {
|
||||
output.push('myStr = "' + myStr + '"');
|
||||
} else {
|
||||
output.push('myStr is not a string');
|
||||
}
|
||||
return output.join('\n');
|
||||
})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myName;
|
||||
var myStr;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myName = "Bob";
|
||||
var myStr = "My name is " + myName + " and I am well!";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 For 循环反向遍历数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2R6BHa'
|
||||
forumTopicId: 16808
|
||||
dashedName: count-backwards-with-a-for-loop
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -47,5 +48,28 @@ assert(code.match(/myArray.push/));
|
||||
assert.deepEqual(myArray, [9, 7, 5, 3, 1]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
for (var i = 9; i > 0; i -= 2) {
|
||||
myArray.push(i);
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 21点游戏
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c6KE7ty'
|
||||
forumTopicId: 16809
|
||||
dashedName: counting-cards
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -152,5 +153,48 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
|
||||
function cc(card) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
return "Change Me";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
cc(2); cc(3); cc(7); cc('K'); cc('A');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
function cc(card) {
|
||||
switch(card) {
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
count++;
|
||||
break;
|
||||
case 10:
|
||||
case 'J':
|
||||
case 'Q':
|
||||
case 'K':
|
||||
case 'A':
|
||||
count--;
|
||||
}
|
||||
if(count > 0) {
|
||||
return count + " Bet";
|
||||
} else {
|
||||
return count + " Hold";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 创建一个小数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ca8GEuW'
|
||||
forumTopicId: 16826
|
||||
dashedName: create-decimal-numbers-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -31,5 +32,24 @@ assert(typeof myDecimal === 'number');
|
||||
assert(myDecimal % 1 != 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){if(typeof myDecimal !== "undefined"){return myDecimal;}})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var ourDecimal = 5.7;
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDecimal = 9.9;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 声明变量
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cNanrHq'
|
||||
forumTopicId: 17556
|
||||
dashedName: declare-javascript-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -42,5 +43,21 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myName !== "undefined"){(function(v){return v;})(myName);}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myName;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 声明字符串变量
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2QvWU6'
|
||||
forumTopicId: 17557
|
||||
dashedName: declare-string-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -56,5 +57,22 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myFirstName !== "undefined" && typeof myLastName !== "undefined"){(function(){return myFirstName + ', ' + myLastName;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myFirstName = "Alan";
|
||||
var myLastName = "Turing";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 数字递减
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cM2KeS2'
|
||||
forumTopicId: 17558
|
||||
dashedName: decrement-a-number-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -51,5 +52,26 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
|
||||
assert(/var myVar = 11;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'myVar = ' + z;})(myVar);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myVar = 11;
|
||||
|
||||
// Only change code below this line
|
||||
myVar = myVar - 1;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myVar = 11;
|
||||
myVar--;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 删除对象的属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cDqKdTv'
|
||||
forumTopicId: 17560
|
||||
dashedName: delete-properties-from-a-javascript-object
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -30,5 +31,38 @@ assert(typeof myDog === 'object' && myDog.tails === undefined);
|
||||
assert(code.match(/"tails": 1/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return z;})(myDog);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"],
|
||||
"bark": "woof"
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"],
|
||||
"bark": "woof"
|
||||
};
|
||||
delete myDog.tails;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 两个小数相除
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cBZe9AW'
|
||||
forumTopicId: 18255
|
||||
dashedName: divide-one-decimal-by-another-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -34,5 +35,22 @@ quotient 变量应该只被赋值一次。
|
||||
assert(code.match(/quotient/g).length === 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y){return 'quotient = '+y;})(quotient);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var quotient = 0.0 / 2.0; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var quotient = 4.4 / 2.0;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 除法运算
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cqkbdAr'
|
||||
forumTopicId: 17566
|
||||
dashedName: divide-one-number-by-another-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -36,5 +37,22 @@ assert(quotient === 2);
|
||||
assert(/\d+\s*\/\s*\d+/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'quotient = '+z;})(quotient);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var quotient = 66 / 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var quotient = 66 / 33;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 字符串中的转义序列
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cvmqRh6'
|
||||
forumTopicId: 17567
|
||||
dashedName: escape-sequences-in-strings
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -72,5 +73,24 @@ assert(/SecondLine\nThirdLine/.test(myStr));
|
||||
assert(myStr === 'FirstLine\n\t\\SecondLine\nThirdLine');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
if (myStr !== undefined){
|
||||
console.log('myStr:\n' + myStr);}})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 转义字符串中的引号
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2QvgSr'
|
||||
forumTopicId: 17568
|
||||
dashedName: escaping-literal-quotes-in-strings
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -38,5 +39,28 @@ assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2);
|
||||
assert(myStr === 'I am a "double quoted" string inside "double quotes".');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){
|
||||
if(typeof myStr === 'string') {
|
||||
console.log("myStr = \"" + myStr + "\"");
|
||||
} else {
|
||||
console.log("myStr is undefined");
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr = ""; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 查找字符串的长度
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cvmqEAd'
|
||||
forumTopicId: 18182
|
||||
dashedName: find-the-length-of-a-string
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -41,5 +42,24 @@ assert(typeof lastNameLength !== 'undefined' && lastNameLength === 8);
|
||||
assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var lastNameLength = 0;
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
lastNameLength = lastName;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var lastNameLength = 0;
|
||||
var lastName = "Lovelace";
|
||||
lastNameLength = lastName.length;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 求余运算
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cWP24Ub'
|
||||
forumTopicId: 18184
|
||||
dashedName: finding-a-remainder-in-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -46,5 +47,24 @@ assert(remainder === 2);
|
||||
assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y){return 'remainder = '+y;})(remainder);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
|
||||
var remainder;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var remainder = 11 % 3;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 JavaScript 生成随机分数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cyWJJs3'
|
||||
forumTopicId: 18185
|
||||
dashedName: generate-random-fractions-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -39,5 +40,31 @@ assert((randomFraction() + '').match(/\./g));
|
||||
assert(code.match(/Math\.random/g).length >= 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){return randomFraction();})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function randomFraction() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
return 0;
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function randomFraction() {
|
||||
return Math.random();
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 JavaScript 生成随机整数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cRn6bfr'
|
||||
forumTopicId: 18186
|
||||
dashedName: generate-random-whole-numbers-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -59,5 +60,29 @@ assert(
|
||||
assert(code.match(/Math.floor/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){return randomWholeNum();})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function randomWholeNum() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
return Math.random();
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function randomWholeNum() {
|
||||
return Math.floor(Math.random() * 10);
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 生成某个范围内的随机整数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cm83yu6'
|
||||
forumTopicId: 18187
|
||||
dashedName: generate-random-whole-numbers-within-a-range
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -59,5 +60,41 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
var calcMin = 100;
|
||||
var calcMax = -100;
|
||||
for(var i = 0; i < 100; i++) {
|
||||
var result = randomRange(5,15);
|
||||
calcMin = Math.min(calcMin, result);
|
||||
calcMax = Math.max(calcMax, result);
|
||||
}
|
||||
(function(){
|
||||
if(typeof myRandom === 'number') {
|
||||
return "myRandom = " + myRandom;
|
||||
} else {
|
||||
return "myRandom undefined";
|
||||
}
|
||||
})()
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function randomRange(myMin, myMax) {
|
||||
// Only change code below this line
|
||||
return 0;
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function randomRange(myMin, myMax) {
|
||||
return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 全局作用域和函数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cQM7mCN'
|
||||
forumTopicId: 18193
|
||||
dashedName: global-scope-and-functions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -44,5 +45,84 @@ assert(/var\s+myGlobal/.test(code));
|
||||
assert(typeof oopsGlobal != 'undefined' && oopsGlobal === 5);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
var logOutput = "";
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
logOutput = message;
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
var oopsGlobal;
|
||||
capture();
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
fun1();
|
||||
fun2();
|
||||
uncapture();
|
||||
(function() { return logOutput || "console.log never called"; })();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Declare the myGlobal variable below this line
|
||||
|
||||
|
||||
function fun1() {
|
||||
// Assign 5 to oopsGlobal Here
|
||||
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
function fun2() {
|
||||
var output = "";
|
||||
if (typeof myGlobal != "undefined") {
|
||||
output += "myGlobal: " + myGlobal;
|
||||
}
|
||||
if (typeof oopsGlobal != "undefined") {
|
||||
output += " oopsGlobal: " + oopsGlobal;
|
||||
}
|
||||
console.log(output);
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myGlobal = 10;
|
||||
|
||||
function fun1() {
|
||||
oopsGlobal = 5;
|
||||
}
|
||||
|
||||
function fun2() {
|
||||
var output = "";
|
||||
if(typeof myGlobal != "undefined") {
|
||||
output += "myGlobal: " + myGlobal;
|
||||
}
|
||||
if(typeof oopsGlobal != "undefined") {
|
||||
output += " oopsGlobal: " + oopsGlobal;
|
||||
}
|
||||
console.log(output);
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 函数中的全局作用域和局部作用域
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c2QwKH2'
|
||||
forumTopicId: 18194
|
||||
dashedName: global-vs--local-scope-in-functions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -46,5 +47,32 @@ assert(myOutfit() === 'sweater');
|
||||
assert(/return outerWear/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var outerWear = "T-Shirt";
|
||||
|
||||
function myOutfit() {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return outerWear;
|
||||
}
|
||||
|
||||
myOutfit();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var outerWear = "T-Shirt";
|
||||
function myOutfit() {
|
||||
var outerWear = "sweater";
|
||||
return outerWear;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 高尔夫代码
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9ykNUR'
|
||||
forumTopicId: 18195
|
||||
dashedName: golf-code
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -84,5 +85,51 @@ assert(golfScore(4, 7) === 'Go Home!');
|
||||
assert(golfScore(5, 9) === 'Go Home!');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
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
|
||||
}
|
||||
|
||||
golfScore(5, 4);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function golfScore(par, strokes) {
|
||||
if (strokes === 1) {
|
||||
return "Hole-in-one!";
|
||||
}
|
||||
|
||||
if (strokes <= par - 2) {
|
||||
return "Eagle";
|
||||
}
|
||||
|
||||
if (strokes === par - 1) {
|
||||
return "Birdie";
|
||||
}
|
||||
|
||||
if (strokes === par) {
|
||||
return "Par";
|
||||
}
|
||||
|
||||
if (strokes === par + 1) {
|
||||
return "Bogey";
|
||||
}
|
||||
|
||||
if(strokes === par + 2) {
|
||||
return "Double Bogey";
|
||||
}
|
||||
|
||||
return "Go Home!";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 数字递增
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ca8GLT9'
|
||||
forumTopicId: 18201
|
||||
dashedName: increment-a-number-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -52,5 +53,26 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
|
||||
assert(/var myVar = 87;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'myVar = ' + z;})(myVar);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myVar = 87;
|
||||
|
||||
// Only change code below this line
|
||||
myVar = myVar + 1;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myVar = 87;
|
||||
myVar++;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用赋值运算符初始化变量
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cWJ4Bfb'
|
||||
forumTopicId: 301171
|
||||
dashedName: initializing-variables-with-the-assignment-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -26,5 +27,21 @@ forumTopicId: 301171
|
||||
assert(/var\s+a\s*=\s*9\s*/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof a !== 'undefined') {(function(a){return "a = " + a;})(a);} else { (function() {return 'a is undefined';})(); }
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 9;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 介绍 else if 语句
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/caeJ2hm'
|
||||
forumTopicId: 18206
|
||||
dashedName: introducing-else-if-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -74,5 +75,36 @@ assert(testElseIf(12) === 'Greater than 10');
|
||||
assert(testElseIf(12) === 'Greater than 10');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testElseIf(val) {
|
||||
if (val > 10) {
|
||||
return "Greater than 10";
|
||||
}
|
||||
|
||||
if (val < 5) {
|
||||
return "Smaller than 5";
|
||||
}
|
||||
|
||||
return "Between 5 and 10";
|
||||
}
|
||||
|
||||
testElseIf(7);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testElseIf(val) {
|
||||
if(val > 10) {
|
||||
return "Greater than 10";
|
||||
} else if(val < 5) {
|
||||
return "Smaller than 5";
|
||||
} else {
|
||||
return "Between 5 and 10";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 介绍 else 语句
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cek4Efq'
|
||||
forumTopicId: 18207
|
||||
dashedName: introducing-else-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -66,5 +67,40 @@ assert(testElse(10) === 'Bigger than 5');
|
||||
assert(/var result = "";/.test(code) && /return result;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function testElse(val) {
|
||||
var result = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val > 5) {
|
||||
result = "Bigger than 5";
|
||||
}
|
||||
|
||||
if (val <= 5) {
|
||||
result = "5 or Smaller";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return result;
|
||||
}
|
||||
|
||||
testElse(4);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function testElse(val) {
|
||||
var result = "";
|
||||
if(val > 5) {
|
||||
result = "Bigger than 5";
|
||||
} else {
|
||||
result = "5 or Smaller";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 For 循环遍历数组的奇数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cm8n7T9'
|
||||
forumTopicId: 18212
|
||||
dashedName: iterate-odd-numbers-with-a-for-loop
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -41,5 +42,28 @@ assert(code.match(/for\s*\(/g).length > 1);
|
||||
assert.deepEqual(myArray, [1, 3, 5, 7, 9]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
for (var i = 1; i < 10; i += 2) {
|
||||
myArray.push(i);
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 For 循环遍历数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/caeR3HB'
|
||||
forumTopicId: 18216
|
||||
dashedName: iterate-through-an-array-with-a-for-loop
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -49,5 +50,30 @@ assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/));
|
||||
assert(!code.match(/total[\s\+\-]*=\s*(\d(?!\s*[;,])|[1-9])/g));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(){if(typeof total !== 'undefined') { return "total = " + total; } else { return "total is undefined";}})()
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
var total = 0;
|
||||
|
||||
for (var i = 0; i < myArr.length; i++) {
|
||||
total += myArr[i];
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: do...while 循环
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cDqWGcp'
|
||||
forumTopicId: 301172
|
||||
dashedName: iterate-with-javascript-do---while-loops
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -67,5 +68,35 @@ assert.deepEqual(myArray, [10]);
|
||||
assert.deepEqual(i, 11);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
var i = 10;
|
||||
|
||||
// Only change code below this line
|
||||
while (i < 5) {
|
||||
myArray.push(i);
|
||||
i++;
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
var i = 10;
|
||||
do {
|
||||
myArray.push(i);
|
||||
i++;
|
||||
} while (i < 5)
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: for 循环
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9yNVCe'
|
||||
forumTopicId: 18219
|
||||
dashedName: iterate-with-javascript-for-loops
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -51,5 +52,28 @@ assert(code.match(/for\s*\(/g).length > 1);
|
||||
assert.deepEqual(myArray, [1, 2, 3, 4, 5]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if (typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
for (var i = 1; i < 6; i++) {
|
||||
myArray.push(i);
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: while 循环
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c8QbnCM'
|
||||
forumTopicId: 18220
|
||||
dashedName: iterate-with-javascript-while-loops
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -43,5 +44,30 @@ assert(code.match(/while/g));
|
||||
assert.deepEqual(myArray, [0, 1, 2, 3, 4]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
var i = 5;
|
||||
while(i >= 0) {
|
||||
myArray.push(i);
|
||||
i--;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 局部作用域和函数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cd62NhM'
|
||||
forumTopicId: 18227
|
||||
dashedName: local-scope-and-functions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -44,5 +45,36 @@ assert(typeof myVar === 'undefined');
|
||||
assert(/var\s+myVar/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function myLocalScope() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
console.log('inside myLocalScope', myVar);
|
||||
}
|
||||
myLocalScope();
|
||||
|
||||
// Run and check the console
|
||||
// myVar is not defined outside of myLocalScope
|
||||
console.log('outside myLocalScope', myVar);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function myLocalScope() {
|
||||
|
||||
// Only change code below this line
|
||||
var myVar;
|
||||
console.log('inside myLocalScope', myVar);
|
||||
}
|
||||
myLocalScope();
|
||||
|
||||
// Run and check the console
|
||||
// myVar is not defined outside of myLocalScope
|
||||
console.log('outside myLocalScope', myVar);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: if else 语句中的逻辑顺序
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cwNvMUV'
|
||||
forumTopicId: 18228
|
||||
dashedName: logical-order-in-if-else-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -73,5 +74,34 @@ assert(orderMyLogic(6) === 'Less than 10');
|
||||
assert(orderMyLogic(11) === 'Greater than or equal to 10');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function orderMyLogic(val) {
|
||||
if (val < 10) {
|
||||
return "Less than 10";
|
||||
} else if (val < 5) {
|
||||
return "Less than 5";
|
||||
} else {
|
||||
return "Greater than or equal to 10";
|
||||
}
|
||||
}
|
||||
|
||||
orderMyLogic(7);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function orderMyLogic(val) {
|
||||
if(val < 5) {
|
||||
return "Less than 5";
|
||||
} else if (val < 10) {
|
||||
return "Less than 10";
|
||||
} else {
|
||||
return "Greater than or equal to 10";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 pop() 操作数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cRbVZAB'
|
||||
forumTopicId: 18236
|
||||
dashedName: manipulate-arrays-with-pop
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -61,5 +62,27 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
// Only change code below this line
|
||||
var removedFromMyArray;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
var removedFromMyArray = myArray.pop();
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 push() 操作数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cnqmVtJ'
|
||||
forumTopicId: 18237
|
||||
dashedName: manipulate-arrays-with-push
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -45,5 +46,26 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'myArray = ' + JSON.stringify(z);})(myArray);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
myArray.push(["dog",3]);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 shift() 操作数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cRbVETW'
|
||||
forumTopicId: 18238
|
||||
dashedName: manipulate-arrays-with-shift
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -50,5 +51,29 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
|
||||
// Only change code below this line
|
||||
var removedFromMyArray;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
|
||||
// Only change code below this line
|
||||
var removedFromMyArray = myArray.shift();
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 unshift() 操作数组
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ckNDESv'
|
||||
forumTopicId: 18239
|
||||
dashedName: manipulate-arrays-with-unshift
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -40,5 +41,28 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y, z){return 'myArray = ' + JSON.stringify(y);})(myArray);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
myArray.shift();
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
myArray.shift();
|
||||
myArray.unshift(["Paul", 35]);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 操作复杂对象
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9yNMfR'
|
||||
forumTopicId: 18208
|
||||
dashedName: manipulating-complex-objects
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -120,5 +121,57 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(x){ if (Array.isArray(x)) { return JSON.stringify(x); } return "myMusic is not an array"})(myMusic);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myMusic = [
|
||||
{
|
||||
"artist": "Billy Joel",
|
||||
"title": "Piano Man",
|
||||
"release_year": 1973,
|
||||
"formats": [
|
||||
"CD",
|
||||
"8T",
|
||||
"LP"
|
||||
],
|
||||
"gold": true
|
||||
}
|
||||
// Add a record here
|
||||
];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myMusic = [
|
||||
{
|
||||
"artist": "Billy Joel",
|
||||
"title": "Piano Man",
|
||||
"release_year": 1973,
|
||||
"formats": [
|
||||
"CS",
|
||||
"8T",
|
||||
"LP" ],
|
||||
"gold": true
|
||||
},
|
||||
{
|
||||
"artist": "ABBA",
|
||||
"title": "Ring Ring",
|
||||
"release_year": 1973,
|
||||
"formats": [
|
||||
"CS",
|
||||
"8T",
|
||||
"LP",
|
||||
"CD",
|
||||
]
|
||||
}
|
||||
];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 通过索引修改数组中的数据
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/czQM4A8'
|
||||
forumTopicId: 18241
|
||||
dashedName: modify-array-data-with-indexes
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -59,5 +60,26 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [18,64,99];
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [18,64,99];
|
||||
myArray[0] = 45;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 在 Switch 语句添加多个相同选项
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cdBKWCV'
|
||||
forumTopicId: 18242
|
||||
dashedName: multiple-identical-options-in-switch-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -102,5 +103,47 @@ assert(!/else/g.test(code) || !/if/g.test(code));
|
||||
assert(code.match(/case/g).length === 9);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function sequentialSizes(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
sequentialSizes(1);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function sequentialSizes(val) {
|
||||
var answer = "";
|
||||
|
||||
switch(val) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
answer = "Low";
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
answer = "Mid";
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
answer = "High";
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 两个小数相乘
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ce2GeHq'
|
||||
forumTopicId: 301173
|
||||
dashedName: multiply-two-decimals-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -30,5 +31,22 @@ assert(product === 5.0);
|
||||
assert(/\*/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(y){return 'product = '+y;})(product);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var product = 2.0 * 0.0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var product = 2.0 * 2.5;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 乘法运算
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cP3y3Aq'
|
||||
forumTopicId: 18243
|
||||
dashedName: multiply-two-numbers-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -36,5 +37,22 @@ assert(product === 80);
|
||||
assert(/\*/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'product = '+z;})(product);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var product = 8 * 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var product = 8 * 10;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 将一个数组嵌套在另一个数组中
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/crZQZf8'
|
||||
forumTopicId: 18247
|
||||
dashedName: nest-one-array-within-another-array
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -22,5 +23,23 @@ forumTopicId: 18247
|
||||
assert(Array.isArray(myArray) && myArray.some(Array.isArray));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [[1,2,3]];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 循环嵌套
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cRn6GHM'
|
||||
forumTopicId: 18248
|
||||
dashedName: nesting-for-loops
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -59,5 +60,34 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function multiplyAll(arr) {
|
||||
var product = 1;
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
return product;
|
||||
}
|
||||
|
||||
multiplyAll([[1,2],[3,4],[5,6,7]]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function multiplyAll(arr) {
|
||||
var product = 1;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
for (var j = 0; j < arr[i].length; j++) {
|
||||
product *= arr[i][j];
|
||||
}
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
multiplyAll([[1,2],[3,4],[5,6,7]]);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 将值传递给带有参数的函数
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cy8rahW'
|
||||
forumTopicId: 18254
|
||||
dashedName: passing-values-to-functions-with-arguments
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -60,5 +61,55 @@ assert(logOutput == 16);
|
||||
assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*;?/m.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
var logOutput = "";
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
if(message) logOutput = JSON.stringify(message).trim();
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
|
||||
capture();
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
uncapture();
|
||||
|
||||
if (typeof functionWithArgs !== "function") {
|
||||
(function() { return "functionWithArgs is not defined"; })();
|
||||
} else {
|
||||
(function() { return logOutput || "console.log never called"; })();
|
||||
}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function functionWithArgs(a, b) {
|
||||
console.log(a + b);
|
||||
}
|
||||
functionWithArgs(10, 5);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 比较不同值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cm8PqCa'
|
||||
forumTopicId: 301174
|
||||
dashedName: practice-comparing-different-values
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -53,5 +54,29 @@ assert(compareEquality('20', 20) === 'Not Equal');
|
||||
assert(code.match(/===/g));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function compareEquality(a, b) {
|
||||
if (a == b) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
compareEquality(10, "10");
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function compareEquality(a,b) {
|
||||
if (a === b) {
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 资料查找
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cDqW2Cg'
|
||||
forumTopicId: 18259
|
||||
dashedName: profile-lookup
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -61,5 +62,90 @@ assert(lookUpProfile('Bob', 'potato') === 'No such contact');
|
||||
assert(lookUpProfile('Akira', 'address') === 'No such property');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var contacts = [
|
||||
{
|
||||
"firstName": "Akira",
|
||||
"lastName": "Laine",
|
||||
"number": "0543236543",
|
||||
"likes": ["Pizza", "Coding", "Brownie Points"]
|
||||
},
|
||||
{
|
||||
"firstName": "Harry",
|
||||
"lastName": "Potter",
|
||||
"number": "0994372684",
|
||||
"likes": ["Hogwarts", "Magic", "Hagrid"]
|
||||
},
|
||||
{
|
||||
"firstName": "Sherlock",
|
||||
"lastName": "Holmes",
|
||||
"number": "0487345643",
|
||||
"likes": ["Intriguing Cases", "Violin"]
|
||||
},
|
||||
{
|
||||
"firstName": "Kristian",
|
||||
"lastName": "Vos",
|
||||
"number": "unknown",
|
||||
"likes": ["JavaScript", "Gaming", "Foxes"]
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
function lookUpProfile(name, prop){
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
lookUpProfile("Akira", "likes");
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var contacts = [
|
||||
{
|
||||
"firstName": "Akira",
|
||||
"lastName": "Laine",
|
||||
"number": "0543236543",
|
||||
"likes": ["Pizza", "Coding", "Brownie Points"]
|
||||
},
|
||||
{
|
||||
"firstName": "Harry",
|
||||
"lastName": "Potter",
|
||||
"number": "0994372684",
|
||||
"likes": ["Hogwarts", "Magic", "Hagrid"]
|
||||
},
|
||||
{
|
||||
"firstName": "Sherlock",
|
||||
"lastName": "Holmes",
|
||||
"number": "0487345643",
|
||||
"likes": ["Intriguing Cases", "Violin"]
|
||||
},
|
||||
{
|
||||
"firstName": "Kristian",
|
||||
"lastName": "Vos",
|
||||
"number": "unknown",
|
||||
"likes": ["JavaScript", "Gaming", "Foxes"]
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
//Write your function in between these comments
|
||||
function lookUpProfile(name, prop){
|
||||
for(var i in contacts){
|
||||
if(contacts[i].firstName === name) {
|
||||
return contacts[i][prop] || "No such property";
|
||||
}
|
||||
}
|
||||
return "No such contact";
|
||||
}
|
||||
//Write your function in between these comments
|
||||
|
||||
lookUpProfile("Akira", "likes");
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 用单引号引用字符串
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cbQmnhM'
|
||||
forumTopicId: 18260
|
||||
dashedName: quoting-strings-with-single-quotes
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -56,5 +57,22 @@ assert(
|
||||
assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function() { return "myStr = " + myStr; })();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 记录集合
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c4mpysg'
|
||||
forumTopicId: 18261
|
||||
dashedName: record-collection
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -93,5 +94,97 @@ assert(!collection[2548].hasOwnProperty('tracks'));
|
||||
assert(updateRecords(1245, 'album', 'Riptide')[1245]['album'] === 'Riptide');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
const _recordCollection = {
|
||||
2548: {
|
||||
albumTitle: 'Slippery When Wet',
|
||||
artist: 'Bon Jovi',
|
||||
tracks: ['Let It Rock', 'You Give Love a Bad Name']
|
||||
},
|
||||
2468: {
|
||||
albumTitle: '1999',
|
||||
artist: 'Prince',
|
||||
tracks: ['1999', 'Little Red Corvette']
|
||||
},
|
||||
1245: {
|
||||
artist: 'Robert Palmer',
|
||||
tracks: []
|
||||
},
|
||||
5439: {
|
||||
albumTitle: 'ABBA Gold'
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var collection = {
|
||||
2548: {
|
||||
albumTitle: 'Slippery When Wet',
|
||||
artist: 'Bon Jovi',
|
||||
tracks: ['Let It Rock', 'You Give Love a Bad Name']
|
||||
},
|
||||
2468: {
|
||||
albumTitle: '1999',
|
||||
artist: 'Prince',
|
||||
tracks: ['1999', 'Little Red Corvette']
|
||||
},
|
||||
1245: {
|
||||
artist: 'Robert Palmer',
|
||||
tracks: []
|
||||
},
|
||||
5439: {
|
||||
albumTitle: 'ABBA Gold'
|
||||
}
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
function updateRecords(object, id, prop, value) {
|
||||
return object;
|
||||
}
|
||||
|
||||
updateRecords(collection, 5439, 'artist', 'ABBA');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var collection = {
|
||||
2548: {
|
||||
albumTitle: 'Slippery When Wet',
|
||||
artist: 'Bon Jovi',
|
||||
tracks: ['Let It Rock', 'You Give Love a Bad Name']
|
||||
},
|
||||
2468: {
|
||||
albumTitle: '1999',
|
||||
artist: 'Prince',
|
||||
tracks: ['1999', 'Little Red Corvette']
|
||||
},
|
||||
1245: {
|
||||
artist: 'Robert Palmer',
|
||||
tracks: []
|
||||
},
|
||||
5439: {
|
||||
albumTitle: 'ABBA Gold'
|
||||
}
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
function updateRecords(object, id, prop, value) {
|
||||
if (value === '') delete object[id][prop];
|
||||
else if (prop === 'tracks') {
|
||||
object[id][prop] = object[id][prop] || [];
|
||||
object[id][prop].push(value);
|
||||
} else {
|
||||
object[id][prop] = value;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
```
|
||||
|
@ -5,6 +5,7 @@ challengeType: 1
|
||||
videoUrl: >-
|
||||
https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/
|
||||
forumTopicId: 301175
|
||||
dashedName: replace-loops-using-recursion
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -67,5 +68,28 @@ assert(!removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
assert(removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function sum(arr, n) {
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function sum(arr, n) {
|
||||
// Only change code below this line
|
||||
if(n <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return sum(arr, n - 1) + arr[n - 1];
|
||||
}
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 用一个 Switch 语句来替代多个 if else 语句
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c3JE8fy'
|
||||
forumTopicId: 18266
|
||||
dashedName: replacing-if-else-chains-with-switch
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -101,5 +102,56 @@ assert(chainToSwitch('John') === '');
|
||||
assert(chainToSwitch(156) === '');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function chainToSwitch(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val === "bob") {
|
||||
answer = "Marley";
|
||||
} else if (val === 42) {
|
||||
answer = "The Answer";
|
||||
} else if (val === 1) {
|
||||
answer = "There is no #1";
|
||||
} else if (val === 99) {
|
||||
answer = "Missed me by this much!";
|
||||
} else if (val === 7) {
|
||||
answer = "Ate Nine";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
chainToSwitch(7);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function chainToSwitch(val) {
|
||||
var answer = "";
|
||||
|
||||
switch(val) {
|
||||
case "bob":
|
||||
answer = "Marley";
|
||||
break;
|
||||
case 42:
|
||||
answer = "The Answer";
|
||||
break;
|
||||
case 1:
|
||||
answer = "There is no #1";
|
||||
break;
|
||||
case 99:
|
||||
answer = "Missed me by this much!";
|
||||
break;
|
||||
case 7:
|
||||
answer = "Ate Nine";
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 函数可以返回某个值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cy87wue'
|
||||
forumTopicId: 18271
|
||||
dashedName: return-a-value-from-a-function-with-return
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -51,5 +52,18 @@ assert(timesFive(2) === 10);
|
||||
assert(timesFive(0) === 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function timesFive(num) {
|
||||
return num * 5;
|
||||
}
|
||||
timesFive(10);
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 函数执行到 return 语句就结束
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cQe39Sq'
|
||||
forumTopicId: 18272
|
||||
dashedName: return-early-pattern-for-functions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -68,5 +69,32 @@ assert(abTest(2, 8) === 18);
|
||||
assert(abTest(3, 3) === 12);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// 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));
|
||||
}
|
||||
|
||||
abTest(2,2);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function abTest(a, b) {
|
||||
if(a < 0 || b < 0) {
|
||||
return undefined;
|
||||
}
|
||||
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 从函数返回布尔值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cp62qAQ'
|
||||
forumTopicId: 18273
|
||||
dashedName: returning-boolean-values-from-functions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -54,5 +55,28 @@ assert(isLess(15, 10) === false);
|
||||
assert(!/if|else/g.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function isLess(a, b) {
|
||||
// Only change code below this line
|
||||
if (a < b) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
isLess(10, 15);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function isLess(a, b) {
|
||||
return a < b;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 Switch 语句从许多选项中进行选择
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c4mv4fm'
|
||||
forumTopicId: 18277
|
||||
dashedName: selecting-from-many-options-with-switch-statements
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -71,5 +72,43 @@ assert(!/else/g.test(code) || !/if/g.test(code));
|
||||
assert(code.match(/break/g).length > 2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function caseInSwitch(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
caseInSwitch(1);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function caseInSwitch(val) {
|
||||
var answer = "";
|
||||
|
||||
switch(val) {
|
||||
case 1:
|
||||
answer = "alpha";
|
||||
break;
|
||||
case 2:
|
||||
answer = "beta";
|
||||
break;
|
||||
case 3:
|
||||
answer = "gamma";
|
||||
break;
|
||||
case 4:
|
||||
answer = "delta";
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 购物清单
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9MEKHZ'
|
||||
forumTopicId: 18280
|
||||
dashedName: shopping-list
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -42,5 +43,53 @@ assert(hasNumber);
|
||||
assert(count > 4);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
var isArray = false;
|
||||
var hasString = false;
|
||||
var hasNumber = false;
|
||||
(function(list){
|
||||
if(Array.isArray(myList)) {
|
||||
isArray = true;
|
||||
if(myList.length > 0) {
|
||||
hasString = true;
|
||||
hasNumber = true;
|
||||
for (var elem of myList) {
|
||||
if(!elem || !elem[0] || typeof elem[0] !== 'string') {
|
||||
hasString = false;
|
||||
}
|
||||
if(!elem || typeof elem[1] !== 'number') {
|
||||
hasNumber = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
count = myList.length;
|
||||
return JSON.stringify(myList);
|
||||
} else {
|
||||
return "myList is not an array";
|
||||
}
|
||||
|
||||
})(myList);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myList = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myList = [
|
||||
["Candy", 10],
|
||||
["Potatoes", 12],
|
||||
["Eggs", 12],
|
||||
["Catfood", 1],
|
||||
["Toads", 9]
|
||||
];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 排队
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ca8Q8tP'
|
||||
forumTopicId: 18307
|
||||
dashedName: stand-in-line
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -49,5 +50,69 @@ nextInLine(testArr, 10);
|
||||
assert(testArr[4] === 10);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
var logOutput = [];
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
logOutput.push(message);
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
|
||||
capture();
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
uncapture();
|
||||
testArr = [1,2,3,4,5];
|
||||
(function() { return logOutput.join("\n");})();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function nextInLine(arr, item) {
|
||||
// Only change code below this line
|
||||
|
||||
return item;
|
||||
// Only change code above this line
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Setup
|
||||
var testArr = [1,2,3,4,5];
|
||||
|
||||
// Display code
|
||||
console.log("Before: " + JSON.stringify(testArr));
|
||||
console.log(nextInLine(testArr, 6));
|
||||
console.log("After: " + JSON.stringify(testArr));
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testArr = [ 1,2,3,4,5];
|
||||
|
||||
function nextInLine(arr, item) {
|
||||
arr.push(item);
|
||||
return arr.shift();
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用 JavaScript 数组将多个值存储在一个变量中
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/crZQWAm'
|
||||
forumTopicId: 18309
|
||||
dashedName: store-multiple-values-in-one-variable-using-javascript-arrays
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -41,5 +42,23 @@ assert(typeof myArray[0] !== 'undefined' && typeof myArray[0] == 'string');
|
||||
assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return z;})(myArray);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = ["The Answer", 42];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用赋值运算符存储值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cEanysE'
|
||||
forumTopicId: 18310
|
||||
dashedName: storing-values-with-the-assignment-operator
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -55,5 +56,34 @@ assert(typeof b === 'number' && b === 7);
|
||||
assert(/b\s*=\s*a\s*;/g.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
if (typeof a != 'undefined') {
|
||||
a = undefined;
|
||||
}
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a){return "a = " + a;})(a);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var a;
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a;
|
||||
a = 7;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 减法运算
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cP3yQtk'
|
||||
forumTopicId: 18314
|
||||
dashedName: subtract-one-number-from-another-with-javascript
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -36,5 +37,22 @@ assert(difference === 12);
|
||||
assert(/var\s*difference\s*=\s*45\s*-\s*[0-9]*;(?!\s*[a-zA-Z0-9]+)/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return 'difference = '+z;})(difference);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var difference = 45 - 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var difference = 45 - 33;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 测试对象的属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cm8Q7Ua'
|
||||
forumTopicId: 18324
|
||||
dashedName: testing-objects-for-properties
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -45,5 +46,26 @@ assert(checkObj('pet') === 'kitten');
|
||||
assert(checkObj('house') === 'Not Found');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function checkObj(obj, checkProp) {
|
||||
// Only change code below this line
|
||||
return "Change Me!";
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function checkObj(obj, checkProp) {
|
||||
if(obj.hasOwnProperty(checkProp)) {
|
||||
return obj[checkProp];
|
||||
} else {
|
||||
return "Not Found";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 了解字符串的不变性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cWPVaUR'
|
||||
forumTopicId: 18331
|
||||
dashedName: understand-string-immutability
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -42,5 +43,28 @@ assert(myStr === 'Hello World');
|
||||
assert(/myStr = "Jello World"/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(v){return "myStr = " + v;})(myStr);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myStr = "Jello World";
|
||||
|
||||
// Only change code below this line
|
||||
myStr[0] = "H"; // Change this line
|
||||
// Only change code above this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "Jello World";
|
||||
myStr = "Hello World";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 理解布尔值
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9Me8t4'
|
||||
forumTopicId: 301176
|
||||
dashedName: understanding-boolean-values
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -31,5 +32,31 @@ assert(typeof welcomeToBooleans() === 'boolean');
|
||||
assert(welcomeToBooleans() === true);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
welcomeToBooleans();
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function welcomeToBooleans() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
return false; // Change this line
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function welcomeToBooleans() {
|
||||
return true; // Change this line
|
||||
}
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 了解变量名区分大小写
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cd6GDcD'
|
||||
forumTopicId: 18334
|
||||
dashedName: understanding-case-sensitivity-in-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -68,5 +69,30 @@ assert(code.match(/properCamelCase/g).length === 2);
|
||||
assert(code.match(/titleCaseOver/g).length === 2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Variable declarations
|
||||
var StUdLyCapVaR;
|
||||
var properCamelCase;
|
||||
var TitleCaseOver;
|
||||
|
||||
// Variable assignments
|
||||
STUDLYCAPVAR = 10;
|
||||
PRoperCAmelCAse = "A String";
|
||||
tITLEcASEoVER = 9000;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var studlyCapVar;
|
||||
var properCamelCase;
|
||||
var titleCaseOver;
|
||||
|
||||
studlyCapVar = 10;
|
||||
properCamelCase = "A String";
|
||||
titleCaseOver = 9000;
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 函数也可以返回 undefined
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ce2p7cL'
|
||||
forumTopicId: 301177
|
||||
dashedName: understanding-undefined-value-returned-from-a-function
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -57,5 +58,40 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
addThree();
|
||||
addFive();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
}
|
||||
|
||||
function addFive() {
|
||||
sum = sum + 5;
|
||||
}
|
||||
|
||||
addThree();
|
||||
addFive();
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 理解未初始化的变量
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cBa2JAL'
|
||||
forumTopicId: 18335
|
||||
dashedName: understanding-uninitialized-variables
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -44,5 +45,35 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = '" + c + "'"; })(a,b,c);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
// Only change code above this line
|
||||
|
||||
a = a + 1;
|
||||
b = b + 5;
|
||||
c = c + " String!";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 10;
|
||||
var c = "I am a";
|
||||
a = a + 1;
|
||||
b = b + 5;
|
||||
c = c + " String!";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 更新对象属性
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/c9yEJT4'
|
||||
forumTopicId: 18336
|
||||
dashedName: updating-object-properties
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -41,5 +42,36 @@ assert(/happy coder/gi.test(myDog.name));
|
||||
assert(/"name": "Coder"/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(z){return z;})(myDog);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
"name": "Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
myDog.name = "Happy Coder";
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用方括号查找字符串中的第一个字符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/ca8JwhW'
|
||||
forumTopicId: 18341
|
||||
dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -35,5 +36,31 @@ assert(firstLetterOfLastName === 'L');
|
||||
assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(v){return v;})(firstLetterOfLastName);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var firstLetterOfLastName = "";
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
firstLetterOfLastName = lastName; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var firstLetterOfLastName = "";
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
firstLetterOfLastName = lastName[0];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用方括号查找字符串中的最后一个字符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cBZQGcv'
|
||||
forumTopicId: 18342
|
||||
dashedName: use-bracket-notation-to-find-the-last-character-in-a-string
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -30,5 +31,27 @@ assert(lastLetterOfLastName === 'e');
|
||||
assert(code.match(/\.length/g).length === 2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(v){return v;})(lastLetterOfLastName);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var lastLetterOfLastName = lastName; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var lastName = "Lovelace";
|
||||
var lastLetterOfLastName = lastName[lastName.length - 1];
|
||||
```
|
||||
|
@ -4,6 +4,7 @@ title: 使用方括号查找字符串中的第N个字符
|
||||
challengeType: 1
|
||||
videoUrl: 'https://scrimba.com/c/cWPVJua'
|
||||
forumTopicId: 18343
|
||||
dashedName: use-bracket-notation-to-find-the-nth-character-in-a-string
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -33,5 +34,27 @@ assert(thirdLetterOfLastName === 'v');
|
||||
assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
(function(v){return v;})(thirdLetterOfLastName);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var thirdLetterOfLastName = lastName; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var lastName = "Lovelace";
|
||||
var thirdLetterOfLastName = lastName[2];
|
||||
```
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user