feat(ch 5): JS second block solved & accesoGenders.html

This commit is contained in:
Rafa Muñoz
2025-03-17 16:29:45 +01:00
parent 63fecbac6a
commit a1fd008a8e
8 changed files with 188 additions and 8 deletions

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function modificarObjeto() {
// Definir un objeto con propiedades vacías
let usuario = {
nombre: "",
edad: null,
ciudad: ""
};
// Pedir datos al usuario y asignarlos al objeto
usuario.nombre = prompt("Introduce tu nombre:");
usuario.edad = parseInt(prompt("Introduce tu edad:")); // Convertir a número
usuario.ciudad = prompt("Introduce tu ciudad:");
// Convertir el objeto a JSON
let usuarioJSON = JSON.stringify(usuario, null, 2);
// Mostrar el objeto en consola y en la página
console.log(usuarioJSON);
document.getElementById("resultado").innerText = usuarioJSON;
}
</script>
</head>
<body>
<button onclick="modificarObjeto()">Modificar Usuario</button>
<pre id="resultado"></pre>
</body>
</html>