Dia 33
This commit is contained in:
15
Practicas/Practicas JS/DOM 6/Ejerccio06_DOM.txt
Normal file
15
Practicas/Practicas JS/DOM 6/Ejerccio06_DOM.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
(Precios sin IVA)
|
||||
Destino: 3 opciones
|
||||
Vuelo: Europa=500, Asia=1000,Africa=1200
|
||||
Número de noches: las que sean
|
||||
Tasas del viaje: Europa=50, Asia=100, Africa=120
|
||||
Coste hotel: 90 por noche
|
||||
Coste alquiler coche: 60 por dia
|
||||
|
||||
|
||||
Coste total: debemos calcularlo con IVA
|
||||
|
||||
|
||||
----------------------------
|
||||
|
||||
BIN
Practicas/Practicas JS/DOM 6/ejercicio06_DOM.png
Normal file
BIN
Practicas/Practicas JS/DOM 6/ejercicio06_DOM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
79
Practicas/Practicas JS/DOM 6/ejercicio06_DOM_version1.html
Normal file
79
Practicas/Practicas JS/DOM 6/ejercicio06_DOM_version1.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<!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>
|
||||
56
Practicas/Practicas JS/DOM 6/index.html
Normal file
56
Practicas/Practicas JS/DOM 6/index.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!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>
|
||||
<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>
|
||||
46
Practicas/Practicas JS/DOM 6/js/main.js
Normal file
46
Practicas/Practicas JS/DOM 6/js/main.js
Normal file
@@ -0,0 +1,46 @@
|
||||
function calculaTotales() {
|
||||
let nDias = 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;
|
||||
}
|
||||
Reference in New Issue
Block a user