Challenge: Access Array Elements
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
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
Expected output:
First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
- 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.
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
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 4. Capítulo 2
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 2.27
Challenge: Access Array Elements
Desliza para mostrar el menú
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
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
Expected output:
First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
- 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.
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
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 4. Capítulo 2