Завдання: Доступ до Елементів Масиву
Завдання
- Створити масив з назвою
stars, що містить такі назви зірок:- "Sirius";
- "Alpha Centauri";
- "Betelgeuse";
- "Polaris".
- Вивести окремі назви зірок, використовуючи різні індекси (0, 1, 2 та 3) за допомогою
console.log
123456const stars = ___; console.log("First element:", ___); // Output: Sirius console.log("Second element:", ___); // Output: Alpha Centauri console.log("Third element:", ___); // Output: Betelgeuse console.log("Forth element:", ___); // Output: Polaris
Очікуваний результат:
First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
- Використання квадратних дужок
[]для створення масиву. - Відокремлення кожного елемента комою
,. - Використання
console.log()для виведення значення елемента масиву за вказаним індексом.
123456const stars = ["Sirius", "Alpha Centauri", "Betelgeuse", "Polaris"]; console.log("First element:", stars[0]); // Output: Sirius console.log("Second element:", stars[1]); // Output: Alpha Centauri console.log("Third element:", stars[2]); // Output: Betelgeuse console.log("Forth element:", stars[3]); // Output: Polaris
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 4. Розділ 2
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Suggested prompts:
Can you explain how array indices work in JavaScript?
What happens if I try to access an index that doesn't exist in the array?
Can you show me how to add another star to the array?
Awesome!
Completion rate improved to 2.27
Завдання: Доступ до Елементів Масиву
Свайпніть щоб показати меню
Завдання
- Створити масив з назвою
stars, що містить такі назви зірок:- "Sirius";
- "Alpha Centauri";
- "Betelgeuse";
- "Polaris".
- Вивести окремі назви зірок, використовуючи різні індекси (0, 1, 2 та 3) за допомогою
console.log
123456const stars = ___; console.log("First element:", ___); // Output: Sirius console.log("Second element:", ___); // Output: Alpha Centauri console.log("Third element:", ___); // Output: Betelgeuse console.log("Forth element:", ___); // Output: Polaris
Очікуваний результат:
First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
- Використання квадратних дужок
[]для створення масиву. - Відокремлення кожного елемента комою
,. - Використання
console.log()для виведення значення елемента масиву за вказаним індексом.
123456const stars = ["Sirius", "Alpha Centauri", "Betelgeuse", "Polaris"]; console.log("First element:", stars[0]); // Output: Sirius console.log("Second element:", stars[1]); // Output: Alpha Centauri console.log("Third element:", stars[2]); // Output: Betelgeuse console.log("Forth element:", stars[3]); // Output: Polaris
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 4. Розділ 2