Repository navigation
Expand file tree
/
Copy pathindex1b.html
More file actions
37 lines (37 loc) · 1.5 KB
/
Copy pathindex1b.html
File metadata and controls
37 lines (37 loc) · 1.5 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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 1b - Obtener el último elemento con at</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main class="lesson">
<header>
<h1>Ejercicio 1b · Obtener el último elemento con at</h1>
</header>
<section aria-labelledby="teoria">
<h2 id="teoria">Antes de empezar</h2>
<p>El método <a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/at" target="_blank" rel="noopener noreferrer">at</a> acepta índices negativos. Un índice negativo cuenta desde el final del array.</p>
<pre><code>const meses = ["enero", "febrero", "marzo"];
console.log(meses.at(-1)); // "marzo"</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>Asigna a <em>ultimoPez</em> el último elemento de <em>peces</em> usando at.</p>
<p>Edita el último <code><script></code>, guarda el archivo y recarga la página.</p>
</section>
<details>
<summary>Resultado esperado</summary>
<pre>Estrella</pre>
</details>
</main>
<script>
const peces = ["Dory", "Nemo", "Estrella"];
let ultimoPez; // Completa la asignación.
console.log(ultimoPez);
</script>
</body>
</html>