Зміст курсу
JavaScript Data Structures
JavaScript Data Structures
Challenge: Array Element Accessor
Task
- Create an array called
stars
with the following star names:- "Sirius";
- "Alpha Centauri";
- "Betelgeuse";
- "Polaris".
- Log individual star names using different indices (0, 1, 2, and 3) using
console.log
const 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
Expected output:
- Use square brackets
[]
to create an array. - Separate each element with the comma
,
. - Use
console.log()
to log the value of the array element at the specified index.
const 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
Дякуємо за ваш відгук!