Dia 35
This commit is contained in:
65
Practicas/Practicas JS/DOM 6 Version 2/index.html
Normal file
65
Practicas/Practicas JS/DOM 6 Version 2/index.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="./js/main.js" defer></script>
|
||||
<title>Document</title>
|
||||
<style>
|
||||
label{
|
||||
display: inline-block;
|
||||
width: 12rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="display: flex; flex-direction: column; max-width: max-content; gap: 10px;">
|
||||
<!-- <div style="display: flex; flex-direction: row; gap: 4px;">
|
||||
<label for="nDias">Introduzca número de dias</label>
|
||||
<input type="text" name="nDias" id="nDias" required>
|
||||
</div> -->
|
||||
<div style="display: flex; gap: 2px;">
|
||||
<label for="destino">Seleccione destino</label>
|
||||
<select name="destino" id="destino" required>
|
||||
<option value=500 selected>Europa</option>
|
||||
<option value=1000>Asia</option>
|
||||
<option value=1200>Africa</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="fechaIda">Fecha de ida</label>
|
||||
<input type="date" name="fechaIda" id="fechaIda" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="fechaRegreso">Fecha de regreso</label>
|
||||
<input type="date" name="fechaRegreso" id="fechaRegreso"required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div style="display: flex; flex-direction: column; gap: 10px;">
|
||||
<div>
|
||||
<label for="costeVuelo">Coste vuelo</label>
|
||||
<input type="text" name="costeVuelo" id="costeVuelo" readonly>
|
||||
</div>
|
||||
<div>
|
||||
<label for="costeHotel">Coste hotel</label>
|
||||
<input type="text" name="costeHotel" id="costeHotel" readonly>
|
||||
</div>
|
||||
<div>
|
||||
<label for="tasasViaje">Tasas viaje</label>
|
||||
<input type="text" name="tasasViaje" id="tasasViaje" readonly>
|
||||
</div>
|
||||
<div>
|
||||
<label for="costeAlquilerCoche">Coste alquiler coche</label>
|
||||
<input type="text" name="costeAlquilerCoche" id="costeAlquilerCoche" readonly>
|
||||
</div>
|
||||
<div>
|
||||
<label for="costeTotal">Coste total</label>
|
||||
<input type="text" name="costeTotal" id="costeTotal" readonly>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<button onclick="calculaTotales()">Calcular coste total</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
54
Practicas/Practicas JS/DOM 6 Version 2/js/main.js
Normal file
54
Practicas/Practicas JS/DOM 6 Version 2/js/main.js
Normal file
@@ -0,0 +1,54 @@
|
||||
function calculaTotales() {
|
||||
|
||||
let nDias = calculaNDias();//document.getElementById("nDias").value;
|
||||
|
||||
let destino = document.getElementById("destino").value;
|
||||
let costeVuelo = document.getElementById("costeVuelo");
|
||||
let costeHotel = document.getElementById("costeHotel");
|
||||
let tasasViaje = document.getElementById("tasasViaje");
|
||||
let costeAlquilerCoche = document.getElementById("costeAlquilerCoche");
|
||||
let costeTotal = document.getElementById("costeTotal");
|
||||
|
||||
let PVPHOTEL;
|
||||
let PVPALQUILERCOCHE =
|
||||
parseInt(nDias) >= 7 ? 40 : parseInt(nDias) <= 3 ? 80 : 60;
|
||||
let IVA = 1.21;
|
||||
|
||||
let tasas = 0;
|
||||
switch (destino) {
|
||||
case "500":
|
||||
tasas = 50;
|
||||
PVPHOTEL = 90;
|
||||
break;
|
||||
case "1000":
|
||||
tasas = 100;
|
||||
PVPHOTEL = 110;
|
||||
break;
|
||||
case "1200":
|
||||
tasas = 120;
|
||||
PVPHOTEL = 80;
|
||||
break;
|
||||
}
|
||||
if (nDias >= 12) {
|
||||
tasas = 0;
|
||||
}
|
||||
|
||||
let vuelo = parseInt(destino);
|
||||
let hotel = nDias * PVPHOTEL;
|
||||
let alquilerCoche = nDias * PVPALQUILERCOCHE;
|
||||
let total = parseFloat((vuelo + hotel + tasas + alquilerCoche) * IVA).toFixed(
|
||||
2
|
||||
);
|
||||
|
||||
costeVuelo.value = vuelo;
|
||||
costeHotel.value = hotel;
|
||||
tasasViaje.value = tasas;
|
||||
costeAlquilerCoche.value = alquilerCoche;
|
||||
costeTotal.value = total;
|
||||
}
|
||||
|
||||
function calculaNDias(){
|
||||
let inicio=new Date(document.getElementById("fechaIda").value);
|
||||
let fin=new Date(document.getElementById("fechaRegreso").value);
|
||||
return Math.ceil((fin-inicio) / (1000 * 60 * 60 * 24));
|
||||
}
|
||||
Reference in New Issue
Block a user