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,27 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function convertirJSON() {
// Definir un JSON como string
let jsonString = '{ "producto": "Laptop", "precio": 800 }';
// Convertir el string JSON a objeto
let objeto = JSON.parse(jsonString);
// Mostrar las propiedades en la consola
console.log("Producto:", objeto.producto);
console.log("Precio:", objeto.precio);
// Mostrar el resultado en la página
document.getElementById("resultado").innerText =
"Producto: " + objeto.producto + "\nPrecio: " + objeto.precio + " €";
}
</script>
</head>
<body>
<button onclick="convertirJSON()">Convertir JSON</button>
<pre id="resultado"></pre>
</body>
</html>