-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcajero.js
More file actions
66 lines (55 loc) · 1.09 KB
/
cajero.js
File metadata and controls
66 lines (55 loc) · 1.09 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Billete
{
constructor(v,c)
{
this.valor = v;
this.cantidad = c;
}
}
function entregarDinero() {
var t = document.getElementById("dinero");
dinero = parseInt(t.value);
for(var b of cajas){
if(dinero > 0)
{
div = Math.floor(dinero/b.valor);
if(div > b.cantidad)
{
papeles = b.cantidad;
}
else
{
papeles = div;
}
entregado.push(new Billete(b.valor, papeles));
dinero = dinero - (b.valor * papeles);
}
}
if(dinero > 0)
{
resultado.innerHTML = "Soy un cajero malo y no te puedo dar esa cantidad de dinero";
}
else
{
for (var e of entregado)
{
if(e.cantidad>0)
{
resultado.innerHTML += e.cantidad + " billetes de $" + e.valor + "<br>";
}
}
}
}
var cajas = [];
var entregado = [];
cajas.push(new Billete(100,10));
cajas.push(new Billete(50,10));
cajas.push(new Billete(20,30));
cajas.push(new Billete(10,10));
cajas.push(new Billete(5,10));
var dinero = 0;
var div = 0;
var papeles = 0;
var b = document.getElementById("Extraer");
var resultado = document.getElementById("resultado");
b.addEventListener("click", entregarDinero);