mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/LMSGI-2024-25.git
synced 2025-11-10 02:13:05 +01:00
feat(ch 5): JS second block solved & accesoGenders.html
This commit is contained in:
32
Unidad_05_Javascript/ejercicios/bloque02/ejercicio03.html
Normal file
32
Unidad_05_Javascript/ejercicios/bloque02/ejercicio03.html
Normal 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>
|
||||
Reference in New Issue
Block a user