* 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>
1.2 KiB
1.2 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56104e9e514f539506016a5c | 使用 For 循环遍历数组的奇数 | 1 | https://scrimba.com/c/cm8n7T9 | 18212 | iterate-odd-numbers-with-a-for-loop |
--description--
for循环可以按照我们指定的顺序来迭代,通过更改我们的计数器
,我们可以按照偶数顺序来迭代。
初始化i = 0
,当i < 10
的时候继续循环。
i += 2
让i
每次循环之后增加2。
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
循环结束后,ourArray
的值为[0,2,4,6,8]
。 改变计数器
,这样我们可以用奇数来数。
--instructions--
写一个for
循环,把从 1 到 9 的奇数添加到myArray
。
--hints--
你应该使用for
循环。
assert(code.match(/for\s*\(/g).length > 1);
myArray
应该等于[1,3,5,7,9]
。
assert.deepEqual(myArray, [1, 3, 5, 7, 9]);
--seed--
--after-user-code--
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
--seed-contents--
// Setup
var myArray = [];
// Only change code below this line
--solutions--
var myArray = [];
for (var i = 1; i < 10; i += 2) {
myArray.push(i);
}