final-expression
, podemos contar por números pares.
Comenzaremos en i = 0
y haremos un bucle mientras que i < 10
. Incrementaremos i
en 2 en cada bucle con i += 2
.
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
ourArray
ahora contendrá [0,2,4,6,8]
.
Cambiemos nuestra initialization
para que podamos contar por números impares.
myArray
usando un bucle for
.
for
bucle para esto.
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a for
loop for this.");'
- text: ' myArray
debería ser igual a [1,3,5,7,9]
.'
testString: 'assert.deepEqual(myArray, [1,3,5,7,9], "myArray
should equal [1,3,5,7,9]
.");'
```