This commit is contained in:
Marcos Lopez 2024-01-25 13:45:32 +01:00
parent af55650a42
commit a32d41503d
7 changed files with 401 additions and 1 deletions

View File

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>DOM 07</title>
<script>
function muestraFechaMs() {
let ms = new Date().getTime();

View File

@ -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>

View 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>

View 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));
}

View File

@ -0,0 +1,28 @@
Hacer una aplicación que calcule el coste de alquiler de un vehículo con las siguientes condiciones:
- Input para indicar los días de alquiler.
- Selector de fecha de inicio del alquiler.
- Tres tipos de vehículo
Básico (45 Euros por día de alquiler)
Gama media (65 Euros por día de alquiler)
Lujo (85 Euros por día de alquiler)
- Elementos opcionales
Silla Infantil(15 Euros por día de alquiler)
Gps(5 Euros por día de alquiler)
- Seguro a terceros (10 Euros día)(Obligatorio, se informa al cliente).
- Seguro a todo riesgo (Opcional)
Para Básico (15 Euros por día de alquiler)
Para Gama media (25 Euros por día de alquiler)
Para Lujo (35 Euros por día de alquiler)
- Conductor con menos de 30 años (recargo de 30% sobre el precio final con Iva)
Debemos dar el precio final con IVA
Y mediante alerta el siguiente mensaje:
Faltan 2 días para tu alquiler !
Tu fecha de de entrega del vehículo es el 27/1/2024 !

View File

@ -0,0 +1,59 @@
<!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"></script>
<title>Alquiler de coche</title>
</head>
<body>
<div style="display: flex; flex-direction: column; min-width: max-content; gap: 4px;">
<div>
<label for="diasAlquiler">Dias de alquiler </label><input type="number" name="diasAlquiler" id="diasAlquiler">
</div>
<div>
<label for="fechaInicio">Fecha de inicio del alquiler </label><input type="date" name="fechaInicio"
id="fechaInicio">
</div>
<div style="display: flex; gap: 2px;">
<label for="tipoVehiculo">Tipo de vehiculo</label>
<select name="tipoVehiculo" id="tipoVehiculo">
<option value='basico' selected>Basico (45€ dia)</option>
<option value='gama_media'>Gama media (65€ dia)</option>
<option value='lujo'>Lujo (85 dia)</option>
</select>
</div>
<div>
<input type="checkbox" name="sillaInfantil" id="sillaInfantil">
<label for="sillaInfantil">Silla infantil (15€ dia)</label>
</div>
<div>
<input type="checkbox" name="gps" id="gps">
<label for="gps">GPS (5€ dia)</label>
</div>
<div>
<div>
<input type="radio" name="seguro" value="10" checked required> Seguro a terceros obligatorio si no se
contrata otro superior (10€ dia)
</div>
<input type="radio" name="seguro" value="0"> Todo riesgo (15€ para basico 25€ para gamam media 35€ para lujo)
</div>
<div>
<input type="checkbox" name="menor30" id="menor30" required>
<label for="menor30">Menor de 30 años (Recargo del 30% sobre el precio final)</label>
</div>
<div>
<button onclick="calculaAlquiler()">Calcula total</button>
</div>
<span id="resultado"></span>
</div>
</body>
</html>

View File

@ -0,0 +1,88 @@
function calculaAlquiler() {
const IVA = 1.21;
const resultado = document.getElementById("resultado");
const diasAlquiler = parseInt(document.getElementById("diasAlquiler").value);
const fechaInicio = new Date(document.getElementById("fechaInicio").value);
const diasHastaRecojer = diasDiferencia(fechaInicio);
//prettier-ignore
const eurXVehiculo = parseInt(eurXTipo(document.getElementById("tipoVehiculo").value));
//prettier-ignore
const sillaInfantil = document.getElementById("sillaInfantil").checked ? 15 : 0;
const gps = document.getElementById("gps").checked ? 5 : 0;
let seguro = parseInt(
document.querySelector('input[name="seguro"]:checked').value
);
if (seguro === 0) {
seguro = parseInt(
eurXSeguro(document.getElementById("tipoVehiculo").value)
);
}
const menor30 = document.getElementById("menor30").checked;
let pvpSinIva =
eurXVehiculo * diasAlquiler +
sillaInfantil * diasAlquiler +
gps * diasAlquiler +
seguro * diasAlquiler;
let pvpConIva = 0;
if (menor30 === true) {
pvpConIva = pvpSinIva * IVA * 1.3;
} else {
pvpConIva = pvpSinIva * IVA;
}
resultado.textContent = `El total final es: ${pvpConIva.toFixed(2)}`;
alert(
`Faltan ${diasHastaRecojer} dias para tu alquiler! \n Tu fecha de entrega del vehículo es el ${formatFecha(
fechaInicio
)} `
);
}
function eurXTipo(tipoVehiculo) {
let valor = 0;
switch (tipoVehiculo) {
case "basico":
valor = 45;
break;
case "gama_media":
valor = 65;
break;
case "lujo":
valor = 85;
break;
}
return valor;
}
function eurXSeguro(tipoVehiculo) {
let valor = 0;
switch (tipoVehiculo) {
case "basico":
valor = 15;
break;
case "gama_media":
valor = 25;
break;
case "lujo":
valor = 35;
break;
}
return valor;
}
function diasDiferencia(fechaFinal) {
const fechaActual = new Date();
return Math.ceil((fechaFinal - fechaActual) / (1000 * 60 * 60 * 24));
}
function formatFecha(fecha) {
var dia = fecha.getDate();
var mes = fecha.getMonth() + 1;
var ano = fecha.getFullYear();
return `${dia}/${mes}/${ano}`;
}