Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-odd-numbers-with-a-for-loop.md
2023-01-30 18:58:54 +02:00

1.6 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56104e9e514f539506016a5c Ітерація непарних чисел за допомогою циклу for 1 https://scrimba.com/c/cm8n7T9 18212 iterate-odd-numbers-with-a-for-loop

--description--

Цикли for не обов’язково повинні додавати одиницю кожної ітерації. Змінюючи наш final-expression, ми можемо перерахувати лише парні числа.

Розпочнемо з i = 0 та створимо цикл, коли i < 10. Кожного циклу ми збільшуватимемо i на 2 за допомогою i += 2.

const ourArray = [];

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

Тепер ourArray міститиме [0, 2, 4, 6, 8]. Змінимо нашу initialization так, щоб ми могли перерахувати непарні числа.

--instructions--

Додайте непарні числа від 1 до 9 до myArray, використовуючи цикл for.

--hints--

Ви повинні використати цикл for.

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

myArray має дорівнювати [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);
}