mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/LMSGI-2024-25.git
synced 2025-11-09 18:03:06 +01:00
33 lines
1.0 KiB
HTML
33 lines
1.0 KiB
HTML
<!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>
|