1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56104e9e514f539506016a5c | Iterate Odd Numbers With a For Loop | 1 | 使用For循环迭代奇数 |
Description
final-expression
,我们可以计算偶数。我们将从i = 0
开始并在i < 10
循环。我们会增加i
的2每个回路与i += 2
。 var ourArray = [];
for(var i = 0; i <10; i + = 2){
ourArray.push(ⅰ);
}
ourArray
现在包含[0,2,4,6,8]
。让我们改变initialization
这样我们就可以用奇数来计算。 Instructions
for
循环将奇数从1到9推送到myArray
。 Tests
tests:
- text: 你应该为此使用<code>for</code>循环。
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
- text: '<code>myArray</code>应该等于<code>[1,3,5,7,9]</code> 。'
testString: 'assert.deepEqual(myArray, [1,3,5,7,9], "<code>myArray</code> should equal <code>[1,3,5,7,9]</code>.");'
Challenge Seed
// Example
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
After Test
console.info('after the test');
Solution
// solution required