2.3 KiB
2.3 KiB
id, title, localeTitle, challengeType
id | title | localeTitle | challengeType |
---|---|---|---|
56105e7b514f539506016a5e | Count Backwards With a For Loop | Contar hacia atrás con un bucle for | 1 |
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 = [];
for (var i=10; i > 0; i-=2) {
ourArray.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 con 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
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
var myArray = [];
for (var i = 9; i > 0; i -= 2) {
myArray.push(i);
}