freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../basic-javascript/iterate-odd-numbers-with-a-...

1.8 KiB

id title challengeType videoUrl localeTitle
56104e9e514f539506016a5c Iterate Odd Numbers With a For Loop 1 Iterar números impares con un bucle for

Description

Para que los bucles no tengan que iterar uno a la vez. Al cambiar nuestra final-expression , podemos contar por números pares. Comenzaremos en i = 0 y haremos un bucle mientras i < 10 . Incrementaremos i en 2 en cada bucle con i += 2 .
var ourArray = [];
para (var i = 0; i <10; i + = 2) {
nuestroArray.push (i);
}
ourArray ahora contendrá [0,2,4,6,8] . Cambiemos nuestra initialization para que podamos contar por números impares.

Instructions

Empuje los números impares del 1 al 9 a 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> debe 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

// solution required