98 lines
2.8 KiB
HTML
98 lines
2.8 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
|
|
if (dias>7) {
|
|
cocheT=dias*40;
|
|
}else{
|
|
if (dias<4){
|
|
cocheT=dias*80;}
|
|
else{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;
|
|
document.getElementById("hotel").value=dias*90;
|
|
}
|
|
|
|
if (destino === "asia") {
|
|
document.getElementById("viaje").value=100;
|
|
document.getElementById("vuelo").value=1000;
|
|
document.getElementById("hotel").value=dias*110;
|
|
}
|
|
|
|
if (destino === "africa") {
|
|
document.getElementById("viaje").value=120;
|
|
document.getElementById("vuelo").value=1200;
|
|
document.getElementById("hotel").value=dias*80;
|
|
}
|
|
|
|
|
|
if (dias>11){
|
|
document.getElementById("viaje").value=0;
|
|
}
|
|
|
|
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> |