Dia 26
This commit is contained in:
12
Practicas/Practicas JS/Practica 2/index.html
Normal file
12
Practicas/Practicas JS/Practica 2/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="./main.js" defer></script>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
25
Practicas/Practicas JS/Practica 2/main.js
Normal file
25
Practicas/Practicas JS/Practica 2/main.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var precioProducto = parseFloat(prompt("Introduce el precio del producto"));
|
||||
var unidades = parseInt(prompt("Introduce el numero de unidades"));
|
||||
|
||||
if (precioProducto>0 && !isNaN(precioProducto) && unidades > 0 && !isNaN(unidades)) {
|
||||
var precioNeto = precioProducto * unidades;
|
||||
var precioTotalConIVA = precioNeto * 1.21;
|
||||
|
||||
if (confirm("¿Desea aplicar un descuento del 15%?")) {
|
||||
var precioConDescuento = precioTotalConIVA * 0.85;
|
||||
alert(
|
||||
`Gracias por tu compra. El importe con descuento del 15% es:
|
||||
${precioConDescuento.toFixed(2)}€`
|
||||
);
|
||||
} else if (confirm("Vale, vale, ¿que le parece del 20%?")) {
|
||||
var nuevoPrecioConDescuento = precioTotalConIVA * 0.8;
|
||||
alert(
|
||||
`¡Eres un buen comprador! Como oferta especial, el importe con descuento del 20% es:
|
||||
${nuevoPrecioConDescuento.toFixed(2)}€`
|
||||
);
|
||||
} else {
|
||||
alert('$·%"·$%/&"$%·%');
|
||||
}
|
||||
} else {
|
||||
alert("Los datos introducidos son incorrectos");
|
||||
}
|
||||
Reference in New Issue
Block a user