Dia 33
This commit is contained in:
parent
ad40171fb4
commit
b83034e0ab
62
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.html
Normal file
62
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.html
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<!Doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Compra caja JAVASCRIPT</title>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
// Escribir mensaje en el input
|
||||
function mensaje() {
|
||||
// Obtener datos de los inputs
|
||||
let nombre = document.getElementById("nombre").value;
|
||||
let material = document.getElementById("material").value;
|
||||
let tamano = document.querySelector("[name=tamano]:checked").value;
|
||||
let comentarios = document.getElementById("comentarios").value;
|
||||
|
||||
// Ver en consola
|
||||
console.log(nombre, material, tamano, comentarios);
|
||||
// Escribir mensaje en el input
|
||||
document.getElementById("respuesta").value = "Hola " + nombre + " has pedido una caja de " + material + " de tamaño " + tamano + ". " + comentarios;
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
||||
<p>Nombre cliente</p>
|
||||
<input type="text" name="nombre" id="nombre">
|
||||
<p>Material de la caja
|
||||
<!-- Lista de selección -->
|
||||
<select name="material" id="material">
|
||||
<option value="madera">Madera</option>
|
||||
<option value="metal">Metal</option>
|
||||
<option value="plastico">Plástico</option>
|
||||
</select></p>
|
||||
|
||||
<p>Seleccione un tamaño para la caja</p>
|
||||
<br/>
|
||||
<input type="radio" value="diminuta" name="tamano">Diminuta<br>
|
||||
<input type="radio" value="mediana" name="tamano" checked>Mediana<br>
|
||||
<input type="radio" value="grande" name="tamano">Grande<br>
|
||||
<br>
|
||||
<p>Comentarios</p>
|
||||
<!-- Área de texto -->
|
||||
<textarea name="opinion" rows="10" cols="60" id="comentarios"></textarea>
|
||||
<br>
|
||||
|
||||
<input type="submit" value="Enviar" onclick="mensaje()">
|
||||
<input type="text" name="respuesta" id="respuesta" size="80">
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.png
Normal file
BIN
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
56
Practicas/Practicas JS/DOM 05/index.html
Normal file
56
Practicas/Practicas JS/DOM 05/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"></script>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="display: flex; flex-direction: column; gap: 1rem; max-width: 500px; margin: 0 auto;">
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<label for="nombre">Nombre del cliente</label>
|
||||
<input type="text" name="nombre" id="nombre" required>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 2px;">
|
||||
<label for="tipoCaja">Material de la caja</label>
|
||||
<select name="tipoCaja" id="tipoCaja" required>
|
||||
<option value="Madera" selected>Madera</option>
|
||||
<option value="Metal">Metal</option>
|
||||
<option value="Plastico">Plastico</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<p style="margin: 0px;">Seleccione unas dimensiones para la caja:</p>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="diminuta" value="diminuta" readonly checked>
|
||||
<label for="dimensiones">Diminuta</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="mediana" value="mediana">
|
||||
<label for="dimensiones">Mediana</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="grande" value="grande">
|
||||
<label for="dimensiones">Grande</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<label for="comentarios">Comentarios</label>
|
||||
<textarea name="comentarios" id="comentarios" cols="30" rows="10"></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button onclick="generaPedido()"> Enviar </button>
|
||||
<span id="resultado" style="border: 1px solid black;"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
11
Practicas/Practicas JS/DOM 05/js/main.js
Normal file
11
Practicas/Practicas JS/DOM 05/js/main.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
function generaPedido(){
|
||||
let txtNombre = document.getElementById("nombre").value;
|
||||
let slbMaterial = document.getElementById("tipoCaja").value;
|
||||
let chkDimensiones = document.querySelector('input[name="dimensiones"]:checked').value;
|
||||
let txtComentarios = document.getElementById("comentarios").value;
|
||||
let txtResultado = document.getElementById("resultado");
|
||||
|
||||
let resultado=` ${txtNombre} ha pedido una caja de ${slbMaterial} con unas dimensiones ${chkDimensiones}. ${txtComentarios}`
|
||||
txtResultado.textContent=resultado;
|
||||
}
|
||||
49
Practicas/Practicas JS/DOM 4/ejercicio04_DOM.html
Normal file
49
Practicas/Practicas JS/DOM 4/ejercicio04_DOM.html
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<!Doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Lista de la compra JAVASCRIPT</title>
|
||||
|
||||
<script>
|
||||
|
||||
function eliminar(elemento) {
|
||||
// Utilizar remove
|
||||
elemento.remove();
|
||||
}
|
||||
|
||||
function anadir() {
|
||||
let listaCompra = document.getElementById("listaCompra");
|
||||
let nuevoItem = document.getElementById("anadir").value;
|
||||
|
||||
if (nuevoItem === "") {
|
||||
alert("No has añadido nada");
|
||||
} else {
|
||||
let item = document.createElement("li");
|
||||
item.textContent = nuevoItem;
|
||||
item.addEventListener("dblclick", function() {
|
||||
eliminar(item);
|
||||
});
|
||||
listaCompra.appendChild(item);
|
||||
document.getElementById("anadir").value = "";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
||||
<label>Mi lista de la compra:</label>
|
||||
<input type="text" name="campo" id="anadir">
|
||||
<input type="button" value="Añadir a la lista" onclick="anadir()">
|
||||
|
||||
<ul id="listaCompra"></ul>
|
||||
|
||||
<p>Nota: Puedes eliminar elementos de la lista haciendo doble click sobre ellos</p>
|
||||
</div>
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
18
Practicas/Practicas JS/DOM 4/index.html
Normal file
18
Practicas/Practicas JS/DOM 4/index.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<!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>Ejercicio DOM 4</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<label for="lista">Mi lista de la compra: </label> <input type="text" name="lista" id="txtlista">
|
||||
<button onclick="addElement()">Añadir a la lista</button>
|
||||
</div>
|
||||
<div>
|
||||
<ul id="listUl"></ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
16
Practicas/Practicas JS/DOM 4/js/main.js
Normal file
16
Practicas/Practicas JS/DOM 4/js/main.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
function addElement(){
|
||||
let txtElemento = document.getElementById('txtlista').value;
|
||||
add(txtElemento);
|
||||
}
|
||||
function add(elemento){
|
||||
let listUl = document.getElementById('listUl')
|
||||
let listItem =document.createElement('li');
|
||||
listItem.textContent=elemento;
|
||||
listItem.addEventListener('dblclick',()=>{delElement(listItem)});
|
||||
listUl.appendChild(listItem);
|
||||
}
|
||||
|
||||
function delElement(elemento){
|
||||
elemento.remove();
|
||||
}
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user