2.0 KiB
2.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56105e7b514f539506016a5e | Count Backwards With a For Loop | 1 | 用For循环向后计数 |
Description
initialization
, condition
和final-expression
。我们将从i = 10
开始并在i > 0
循环。我们将递减i
2每个回路与i -= 2
。 var ourArray = [];
for(var i = 10; i> 0; i- = 2){
ourArray.push(ⅰ);
}
ourArray
现在包含[10,8,6,4,2]
。让我们改变initialization
和final-expression
这样我们就可以向后计数两位奇数。 Instructions
for
循环将奇数从9到1推送到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>push</code> 。
testString: 'assert(code.match(/myArray.push/), "You should be using the array method <code>push</code>.");'
- text: '<code>myArray</code>应该等于<code>[9,7,5,3,1]</code> 。'
testString: 'assert.deepEqual(myArray, [9,7,5,3,1], "<code>myArray</code> should equal <code>[9,7,5,3,1]</code>.");'
Challenge Seed
// Example
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
After Test
console.info('after the test');
Solution
// solution required