forked from marquez.juan/clase-10-ejercicios-de-repaso
Compare commits
1 Commits
ejercicios
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52c3871b2b |
@@ -1,26 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
/* Ejercicio 1: Saludo personalizado
|
|
||||||
|
|
||||||
Crear una página con un campo de texto y un botón. Al hacer clic en el botón,
|
|
||||||
leer el valor del campo y mostrar en la página el mensaje `"Hola, [nombre]!"`.
|
|
||||||
Si el campo está vacío, mostrar en su lugar `"Por favor, ingresá tu nombre."`. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const boton = document.querySelector("#boton");
|
|
||||||
|
|
||||||
boton.addEventListener("click", (e) => {
|
|
||||||
|
|
||||||
const nombre = document.querySelector("#nombre").value;
|
|
||||||
|
|
||||||
if (nombre.trim() !== "") {
|
|
||||||
|
|
||||||
document.getElementById("saludo").textContent = `Hola, ${nombre}!`;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
document.getElementById("saludo").textContent = "Por favor, ingresa tu nombre"
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -8,9 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
<input type="text" id="nombre" placeholder="Ingresa tu nombre">
|
|
||||||
<p id="saludo"></p>
|
|
||||||
<button type="submit" id="boton">Enviar</button>
|
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,32 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
/* Ejercicio 2: Lista de tareas simple
|
|
||||||
|
|
||||||
Crear una página con un campo de texto y un botón "Agregar". Cada vez que se
|
|
||||||
haga clic en el botón, agregar el texto del campo como un nuevo ítem en una
|
|
||||||
lista `<ul>`. Después de agregar el ítem, limpiar el campo.
|
|
||||||
|
|
||||||
Si el campo está vacío al hacer clic, no agregar nada. */
|
|
||||||
|
|
||||||
|
|
||||||
function agregar () {
|
|
||||||
|
|
||||||
const comidaNueva = document.getElementById("comidaNueva").value;
|
|
||||||
|
|
||||||
if (comidaNueva.trim() !== "") {
|
|
||||||
|
|
||||||
const nuevoLi = document.createElement("li");
|
|
||||||
|
|
||||||
nuevoLi.textContent = comidaNueva;
|
|
||||||
|
|
||||||
document.getElementById("lista").appendChild(nuevoLi);
|
|
||||||
|
|
||||||
document.getElementById("comidaNueva").value = "";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const boton = document.getElementById("botonAgregar")
|
|
||||||
|
|
||||||
boton.addEventListener("click", agregar);
|
|
||||||
@@ -9,18 +9,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 2</h1>
|
<h1>Ejercicio 2</h1>
|
||||||
|
|
||||||
|
|
||||||
<h2>Comidas tradicionales de Argentina:</h2>
|
|
||||||
<ul id="lista">
|
|
||||||
<li>Asado</li>
|
|
||||||
<li>Empanadas</li>
|
|
||||||
<li>Locro</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Agregar una comida a la lista</h3>
|
|
||||||
<input type="text" id="comidaNueva" placeholder="Escribí otra comida tradicional">
|
|
||||||
<br>
|
|
||||||
<button id="botonAgregar">Agregar</button>
|
|
||||||
<script src="ejercicio2.js"></script>
|
<script src="ejercicio2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1 +1,133 @@
|
|||||||
// Agregar aquí el código javascript
|
const preguntas = [
|
||||||
|
{
|
||||||
|
pregunta: "¿Cuál es la diferencia entre let y const?",
|
||||||
|
opciones: [
|
||||||
|
"No hay diferencia, son equivalentes",
|
||||||
|
"let permite reasignar el valor, const no",
|
||||||
|
"Depende del tipo de datos",
|
||||||
|
"let solo funciona dentro de funciones"
|
||||||
|
],
|
||||||
|
correcta: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pregunta: "¿Qué retorna querySelector si no encuentra ningún elemento?",
|
||||||
|
opciones: ["undefined", "false", "null", "0"],
|
||||||
|
correcta: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pregunta: "¿Qué hace el método filter?",
|
||||||
|
opciones: [
|
||||||
|
"Modifica los elementos del array original",
|
||||||
|
"Retorna el primer elemento que cumple la condición",
|
||||||
|
"Retorna un nuevo array con los elementos que cumplen la condición",
|
||||||
|
"Elimina elementos duplicados del array"
|
||||||
|
],
|
||||||
|
correcta: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pregunta: "¿Cuál es el operador de igualdad estricta en JavaScript?",
|
||||||
|
opciones: ["=", "==", "===", "!="],
|
||||||
|
correcta: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pregunta: "¿Para qué sirve event.preventDefault()?",
|
||||||
|
opciones: [
|
||||||
|
"Detiene la propagación del evento hacia elementos padre",
|
||||||
|
"Evita el comportamiento por defecto del navegador",
|
||||||
|
"Elimina el event listener del elemento",
|
||||||
|
"Pausa la ejecución del código hasta que el evento termine"
|
||||||
|
],
|
||||||
|
correcta: 1
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
let indiceActual = 0;
|
||||||
|
let puntaje = 0;
|
||||||
|
|
||||||
|
const pantalla = document.querySelector("#pantalla-quiz");
|
||||||
|
const resultadoEl = document.querySelector("#resultado");
|
||||||
|
const preguntaEl = document.querySelector("#pregunta");
|
||||||
|
const opcionesEl = document.querySelector("#opciones");
|
||||||
|
const feedbackEl = document.querySelector("#feedback");
|
||||||
|
const btnSiguiente = document.querySelector("#siguiente");
|
||||||
|
const progresoEl = document.querySelector("#progreso");
|
||||||
|
const progressFill = document.querySelector("#progress-fill");
|
||||||
|
const puntajeNumEl = document.querySelector("#puntaje-num");
|
||||||
|
const resultadoMsg = document.querySelector("#resultado-msg");
|
||||||
|
const btnReiniciar = document.querySelector("#reiniciar");
|
||||||
|
|
||||||
|
function mensajeFinal(p, total) {
|
||||||
|
if (p === total) return "¡Perfecto! Todo bien.";
|
||||||
|
if (p >= total * 0.8) return "¡Muy bien!";
|
||||||
|
if (p >= total * 0.6) return "Bien, pero hay margen para mejorar.";
|
||||||
|
return "Vale la pena repasar los temas.";
|
||||||
|
}
|
||||||
|
|
||||||
|
function mostrarPregunta() {
|
||||||
|
const actual = preguntas[indiceActual];
|
||||||
|
|
||||||
|
// Actualizamos el encabezado y la barra de progreso.
|
||||||
|
progresoEl.textContent = `${indiceActual + 1} / ${preguntas.length}`;
|
||||||
|
progressFill.style.width = `${(indiceActual / preguntas.length) * 100}%`;
|
||||||
|
|
||||||
|
preguntaEl.textContent = actual.pregunta;
|
||||||
|
opcionesEl.innerHTML = "";
|
||||||
|
feedbackEl.textContent = "";
|
||||||
|
btnSiguiente.style.display = "none";
|
||||||
|
|
||||||
|
for (let i = 0; i < actual.opciones.length; i++) {
|
||||||
|
const boton = document.createElement("button");
|
||||||
|
boton.className = "opcion";
|
||||||
|
boton.textContent = actual.opciones[i];
|
||||||
|
boton.addEventListener("click", () => responder(i));
|
||||||
|
opcionesEl.appendChild(boton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function responder(indiceRespuesta) {
|
||||||
|
const actual = preguntas[indiceActual];
|
||||||
|
const botones = opcionesEl.querySelectorAll(".opcion");
|
||||||
|
|
||||||
|
// Deshabilitamos todos los botones para que no se pueda responder dos veces.
|
||||||
|
for (const boton of botones) {
|
||||||
|
boton.disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indiceRespuesta === actual.correcta) {
|
||||||
|
botones[indiceRespuesta].classList.add("correcta");
|
||||||
|
feedbackEl.textContent = "¡Correcto!";
|
||||||
|
puntaje++;
|
||||||
|
} else {
|
||||||
|
botones[indiceRespuesta].classList.add("incorrecta");
|
||||||
|
botones[actual.correcta].classList.add("correcta");
|
||||||
|
feedbackEl.textContent = `Incorrecto. La correcta era: "${actual.opciones[actual.correcta]}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSiguiente.style.display = "inline-block";
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSiguiente.addEventListener("click", () => {
|
||||||
|
indiceActual++;
|
||||||
|
|
||||||
|
if (indiceActual < preguntas.length) {
|
||||||
|
mostrarPregunta();
|
||||||
|
} else {
|
||||||
|
// Actualizamos la barra al 100% antes de mostrar el resultado.
|
||||||
|
progressFill.style.width = "100%";
|
||||||
|
|
||||||
|
pantalla.style.display = "none";
|
||||||
|
resultadoEl.style.display = "block";
|
||||||
|
puntajeNumEl.textContent = `${puntaje} / ${preguntas.length}`;
|
||||||
|
resultadoMsg.textContent = mensajeFinal(puntaje, preguntas.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnReiniciar.addEventListener("click", () => {
|
||||||
|
indiceActual = 0;
|
||||||
|
puntaje = 0;
|
||||||
|
resultadoEl.style.display = "none";
|
||||||
|
pantalla.style.display = "block";
|
||||||
|
mostrarPregunta();
|
||||||
|
});
|
||||||
|
|
||||||
|
mostrarPregunta();
|
||||||
|
|||||||
@@ -1,2 +1,168 @@
|
|||||||
/* Agregar el código CSS necesario para el ejercicio */
|
/* Hoja de estilo realizada con IA */
|
||||||
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: system-ui, sans-serif;
|
||||||
|
background: #f5f4f0;
|
||||||
|
color: #1a1a1a;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: #fff;
|
||||||
|
border: 0.5px solid #ddd;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 2rem;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 520px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Encabezado ── */
|
||||||
|
|
||||||
|
.quiz-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quiz-title {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #888;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quiz-progress {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Barra de progreso ── */
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
height: 4px;
|
||||||
|
background: #eee;
|
||||||
|
border-radius: 2px;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
background: #1a1a1a;
|
||||||
|
border-radius: 2px;
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Pregunta ── */
|
||||||
|
|
||||||
|
#pregunta {
|
||||||
|
font-size: 1.05rem;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.5;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
min-height: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Opciones ── */
|
||||||
|
|
||||||
|
#opciones {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opcion {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background: #f5f4f0;
|
||||||
|
border: 0.5px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #1a1a1a;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.15s, border-color 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opcion:hover:not(:disabled) {
|
||||||
|
background: #edecea;
|
||||||
|
border-color: #bbb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opcion:disabled { cursor: default; }
|
||||||
|
|
||||||
|
.opcion.correcta {
|
||||||
|
background: #eaf3de;
|
||||||
|
border-color: #639922;
|
||||||
|
color: #3b6d11;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opcion.incorrecta {
|
||||||
|
background: #fcebeb;
|
||||||
|
border-color: #e24b4a;
|
||||||
|
color: #a32d2d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Feedback ── */
|
||||||
|
|
||||||
|
#feedback {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
min-height: 1.2rem;
|
||||||
|
color: #555;
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Botones de acción ── */
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 0.5px solid #ccc;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover { opacity: 0.85; }
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: transparent;
|
||||||
|
color: #1a1a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Pantalla de resultado ── */
|
||||||
|
|
||||||
|
#resultado {
|
||||||
|
text-align: center;
|
||||||
|
padding: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultado-score {
|
||||||
|
font-size: 3rem;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultado-label {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #888;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultado-msg {
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,36 @@
|
|||||||
<link rel="stylesheet" href="estilo.css">
|
<link rel="stylesheet" href="estilo.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 9</h1>
|
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<div id="pantalla-quiz">
|
||||||
|
<div class="quiz-header">
|
||||||
|
<span class="quiz-title">Ejercicio 9 - Quiz de JavaScript</span>
|
||||||
|
<span class="quiz-progress" id="progreso">1 / 5</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="progress-bar">
|
||||||
|
<div class="progress-fill" id="progress-fill" style="width: 0%"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p id="pregunta"></p>
|
||||||
|
|
||||||
|
<div id="opciones"></div>
|
||||||
|
|
||||||
|
<p id="feedback"></p>
|
||||||
|
|
||||||
|
<button class="btn" id="siguiente" style="display:none">Siguiente →</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="resultado" style="display:none">
|
||||||
|
<p class="resultado-score" id="puntaje-num"></p>
|
||||||
|
<p class="resultado-label">respuestas correctas</p>
|
||||||
|
<p class="resultado-msg" id="resultado-msg"></p>
|
||||||
|
<button class="btn btn-secondary" id="reiniciar">Reiniciar quiz</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="ejercicio9.js"></script>
|
<script src="ejercicio9.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user