2.1 KiB
2.1 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56105e7b514f539506016a5e | Count Backwards With a For Loop | 1 | Contar hacia atrás con un bucle for |
Description
initialization
, condition
y final-expression
. Comenzaremos en i = 10
y haremos un bucle mientras i > 0
. Disminuiremos i
en 2 cada bucle con i -= 2
. var ourArray = [];
para (var i = 10; i> 0; i- = 2) {
nuestroArray.push (i);
}
ourArray
ahora contendrá [10,8,6,4,2]
. Cambiemos nuestra initialization
y final-expression
para que podamos contar hacia atrás de dos en dos 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: Deberías estar usando el método de matriz <code>push</code> .
testString: 'assert(code.match(/myArray.push/), "You should be using the array method <code>push</code>.");'
- text: '<code>myArray</code> debe ser igual a <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