Files
freeCodeCamp/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md
camperbot 0432ec995f chore(i18n,learn): processed translations (#41387)
* chore(i8n,learn): processed translations

* fix: remove extra space

Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
2021-03-07 08:15:14 -08:00

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
cf1111c1c11feddfaeb1bdef Itera con el bucle "while" de JavaScript 1 https://scrimba.com/c/c8QbnCM 18220 iterate-with-javascript-while-loops

--description--

Puedes ejecutar el mismo código múltiples veces usando un bucle.

El primer tipo de bucle que aprenderemos se llama bucle while porque ejecuta una condición específica mientras esta sea verdadera, y se detiene una vez que esa condición ya no sea verdadera.

var ourArray = [];
var i = 0;
while(i < 5) {
  ourArray.push(i);
  i++;
}

En el ejemplo de código anterior, el bucle while se ejecutará 5 veces y añadirá los números de 0 a 4 a ourArray.

Intentemos construir un bucle while para que funcione empujando valores a un arreglo.

--instructions--

Agrega los números de 5 a 0 (inclusivo) en orden descendente a myArray usando un bucle while.

--hints--

Debes utilizar un bucle while para esto.

assert(code.match(/while/g));

myArray debe ser igual a [5,4,3,2,1,0].

assert.deepEqual(myArray, [5, 4, 3, 2, 1, 0]);

--seed--

--after-user-code--

if(typeof myArray !== "undefined"){(function(){return myArray;})();}

--seed-contents--

// Setup
var myArray = [];

// Only change code below this line

--solutions--

var myArray = [];
var i = 5;
while(i >= 0) {
  myArray.push(i);
  i--;
}