IFCD0210/Practicas/Practicas JS/DOM 6/ejercicio06_DOM_version1.html
Marcos Lopez b83034e0ab Dia 33
2024-01-23 13:52:08 +01:00

79 lines
2.4 KiB
HTML

<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Ejercicio 06 JAVASCRIPT Coste viaje</title>
<script>
// Función que obtiene los datos
function obtener() {
let dias=document.getElementById("dias").value;
let destino=document.getElementById("destino").value;
//Precio coche
let cocheT=dias*60;
//Rellenar el input
document.getElementById("coche").value=cocheT;
//Precio noches hotel
let hotelT=dias*90;
//Rellenar el input
document.getElementById("hotel").value=hotelT;
//Precios viaje en función del destino
if (destino === "europa") {
//Tasas // Vuelo
document.getElementById("viaje").value=50;
document.getElementById("vuelo").value=500;
}
if (destino === "asia") {
document.getElementById("viaje").value=100;
document.getElementById("vuelo").value=1000;
}
if (destino === "africa") {
document.getElementById("viaje").value=120;
document.getElementById("vuelo").value=1200;
}
let viaje=parseFloat(document.getElementById("viaje").value);
let avion=parseFloat(document.getElementById("vuelo").value);
let hotel=parseFloat(document.getElementById("hotel").value);
let total=avion+hotel+viaje+cocheT;
let totalI=(total*1.21).toFixed(2);
document.getElementById("total").value=totalI;
}
</script>
</head>
<body>
<div id="container">
<p>Introduzca número de dias
<input type="text" name="dias" id="dias"><br><br>
Seleccione Destino
<!-- Lista de selección -->
<select name="destino" id="destino">
<option value="europa">Europa</option>
<option value="asia">Asia</option>
<option value="africa">África</option>
</select></p>
<br>
<p>Elige el día de salida <input type="date" id="fecha"></p>
<br>
<p>Coste vuelo <input type="text" name="vuelo" id="vuelo"></p>
<p>Coste hotel <input type="text" name="hotel" id="hotel"></p>
<p>Tasas viaje <input type="text" name="viaje" id="viaje"></p>
<p>Coste alquiler coche <input type="text" name="coche" id="coche"></p>
<p>Coste total <input type="text" name="total" id="total" ></p>
<input type="button" value="Calcular coste total" onclick="obtener();">
</div>
<br>
</body>
</html>