Dia 35
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<!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;
|
||||
//Calcular estancia
|
||||
let salida=document.getElementById("fecha").valueAsNumber;
|
||||
let vuelta=document.getElementById("fechaVuelta").valueAsNumber;
|
||||
let dif=vuelta - salida;
|
||||
let dias=Math.ceil(dif/(1000*60*60*24));
|
||||
|
||||
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;
|
||||
console.log(dias);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
||||
|
||||
<p>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>Fechas del viaje</p>
|
||||
<p>Elige el día de salida <input type="date" id="fecha"></p>
|
||||
<p>Elige el día de vuelta <input type="date" id="fechaVuelta"></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>
|
||||
Reference in New Issue
Block a user