Files

1.3 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56104e9e514f539506016a5c Iterar números ímpares com um laço for 1 https://scrimba.com/c/cm8n7T9 18212 iterate-odd-numbers-with-a-for-loop

--description--

Laços for não tem de iterar um de cada vez. Ao alterar nossa final-expression, nós podemos contar os números pares.

Começaremos em i = 0 e um laço while i < 10. Incrementaremos i em 2 a cada iteração com i += 2.

const ourArray = [];

for (let i = 0; i < 10; i += 2) {
  ourArray.push(i);
}

ourArray agora conterá [0, 2, 4, 6, 8]. Vamos mudar nossa initialization para que possamos contar por números ímpares.

--instructions--

Adicione (push) os números ímpares de 9 até 1 para myArray usando um laço for.

--hints--

Você deve estar usando um laço for para isso.

assert(/for\s*\([^)]+?\)/.test(code));

myArray deve ser igual a [1, 3, 5, 7, 9].

assert.deepEqual(myArray, [1, 3, 5, 7, 9]);

--seed--

--after-user-code--

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

--seed-contents--

// Setup
const myArray = [];

// Only change code below this line

--solutions--

const myArray = [];
for (let i = 1; i < 10; i += 2) {
  myArray.push(i);
}