Contador de notas
by Lucaskazama
HTML
Insert value: <input type="text" id="money">
<p id="output"></p>
JavaScript
function calculateChange(value) {
let changeCounter = {'100': 0, '50': 0, '20': 0, '10': 0, '5': 0, '2': 0, '1': 0};
const ballots = [100,50,20,10,5,2,1];
for (var ballot of ballots) {
while (value >= ballot) {
changeCounter[ballot] += 1
value -= ballot
}
}
return changeCounter;
}
$('#money').keyup(function() {
$('#output').html(JSON.stringify(calculateChange(this.value)))
});