mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-13 06:04:13 -04:00
1.9 KiB
1.9 KiB
id, title, localeTitle, challengeType
| id | title | localeTitle | challengeType |
|---|---|---|---|
| 56104e9e514f539506016a5c | Iterate Odd Numbers With a For Loop | Iterar números impares con un bucle for | 1 |
Description
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.
Instructions
myArray usando un bucle for .
Tests
tests:
- text: Usted debe estar usando una <code>for</code> bucle para esto.
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
- text: ' <code>myArray</code> debería ser igual a <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
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
var myArray = [];
for (var i = 1; i < 10; i += 2) {
myArray.push(i);
}