--- id: 56105e7b514f539506016a5e title: Count Backwards With a For Loop challengeType: 1 videoUrl: '' localeTitle: 用For循环向后计数 --- ## Description
只要我们可以定义正确的条件,for循环也可以向后计数。为了向后计数两次,我们需要更改initializationconditionfinal-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] 。让我们改变initializationfinal-expression这样我们就可以向后计数两位奇数。
## Instructions
使用for循环将奇数从9到1推送到myArray
## Tests
```yml tests: - text: 你应该为此使用for循环。 testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a for loop for this.");' - text: 你应该使用数组方法push 。 testString: 'assert(code.match(/myArray.push/), "You should be using the array method push.");' - text: 'myArray应该等于[9,7,5,3,1] 。' testString: 'assert.deepEqual(myArray, [9,7,5,3,1], "myArray should equal [9,7,5,3,1].");' ```
## Challenge Seed
```js // 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
```js console.info('after the test'); ```
## Solution
```js // solution required ```