-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function validarMonto(monto) {
// Verificar si el monto es un número válido
if (isNaN(monto)) {
return false;
}
// Verificar si el monto tiene más de dos decimales
var partes = monto.toString().split(".");
if (partes.length > 1 && partes[1].length > 2) {
return false;
}
// El monto es válido
return true;
}
function convertirDolaresAPesos(dolares) {
// Definir el tipo de cambio
var tipoDeCambio = 745;
// Calcular la cantidad de pesos chilenos
var pesos = dolares * tipoDeCambio;
// Devolver la cantidad de pesos chilenos
return pesos;
}
const montoDolaresInput = document.getElementById("monto-dolares");
const btnCambiar = document.getElementById("btn-enviar");
btnCambiar.addEventListener("click", function(){
let montoDolares = montoDolaresInput.value;
let montoPesos;
if(validarMonto(montoDolares)){
// El monto es válido, hacer algo con él
montoPesos = convertirDolaresAPesos(montoDolares);
alert(montoPesos);
}
else{
// El monto no es válido, mostrar un mensaje de error
alert("El monto ingresado no es válido.");
}
});