* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
cf1111c1c11feddfaeb5bdef | Iterate with JavaScript For Loops | 1 | 使用JavaScript迭代循环 |
Description
for loop
”,因为它“运行”特定次数。 For循环用三个可选表达式声明,用分号分隔: for ([initialization]; [condition]; [final-expression])
initialization
语句仅在循环开始之前执行一次。它通常用于定义和设置循环变量。 condition
语句在每次循环迭代开始时进行计算,并且只要计算结果为true
就会继续。当迭代开始时condition
为false
时,循环将停止执行。这意味着如果condition
以false
开头,则循环将永远不会执行。 final-expression
在每次循环迭代结束时执行,在下一次condition
检查之前执行,通常用于递增或递减循环计数器。在下面的示例中,我们使用i = 0
初始化并迭代,而条件i < 5
为真。我们将在每个循环迭代中将i
递增1
,并使用i++
作为final-expression
。 var ourArray = [];
for(var i = 0; i <5; i ++){
ourArray.push(ⅰ);
}
ourArray
现在包含[0,1,2,3,4]
。 Instructions
for
循环将值1到5推送到myArray
。 Tests
tests:
- text: 你应该为此使用<code>for</code>循环。
testString: assert(code.match(/for\s*\(/g).length > 1);
- text: '<code>myArray</code>应该等于<code>[1,2,3,4,5]</code> 。'
testString: assert.deepEqual(myArray, [1,2,3,4,5]);
Challenge Seed
// Example
var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
After Test
console.info('after the test');
Solution
// solution required