Repository navigation
Expand file tree
/
Copy pathindex3.html
More file actions
47 lines (46 loc) · 1.78 KB
/
Copy pathindex3.html
File metadata and controls
47 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 3 - Detectar un índice fuera del array</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main class="lesson">
<header>
<h1>Ejercicio 3 · Detectar un índice fuera del array</h1>
</header>
<section aria-labelledby="teoria">
<h2 id="teoria">Antes de empezar</h2>
<p>Los índices empiezan en 0. Para tres elementos, los índices que existen son 0, 1 y 2.</p>
<pre><code>const frutas = ["pera", "uva", "kiwi"];
console.log(frutas.length); // 3
console.log(frutas[2]); // "kiwi"</code></pre>
</section>
<section aria-labelledby="practica">
<h2 id="practica">Tu turno</h2>
<p>Abre la consola del navegador (<strong>F12 → Consola</strong>).</p>
<p>Ejecuta el código y explica por qué el último mensaje dice «Pez siguiente: undefined». Como reto adicional, corrige el límite del bucle.</p>
<p>Edita el último <code><script></code>, guarda el archivo y recarga la página.</p>
</section>
<details>
<summary>Resultado esperado</summary>
<p>Antes de corregir el límite, la consola muestra:</p>
<pre>Pez siguiente: Dory
Pez siguiente: Nemo
Pez siguiente: Shipho
Pez siguiente: Estrella
Pez siguiente: undefined</pre>
<p>Después de corregirlo, la última línea desaparece.</p>
</details>
</main>
<script>
let muchos_peces = ["Dory", "Nemo", "Shipho", "Estrella"];
for (let i = 0; i <= muchos_peces.length; i++) {
let siguiente_pez = muchos_peces[i];
console.log("Pez siguiente: " + siguiente_pez);
}
</script>
</body>
</html>