Compute Change
HTML
<body>
<input type="number" class="calculate" id="moneytochange" placeholder="€">
<div id="change">
</div>
</body>
CSS
input {
text-align: center;
font-size: 3vw;
margin: 0 0%;
width: 60%;
border: none;
border-bottom: 4px solid #7C4DFF;
outline: none;
font-family: 'Raleway', sans-serif;
transition: border-radius 0.3s ease-out;
opacity: 50%;
}
input:focus {
border-radius: 1vw;
}
JavaScript
$(document).ready(function(){
$(".calculate").bind("keyup change input paste", function(){
var billsAndCoins = [50000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5, 2, 1];
var number = {};
var money = $("#moneytochange").val();
$("#change").html("");
var cents = money * 100;
billsAndCoins.forEach(function(entry) {
number[entry] = (cents - (cents % entry))/ entry;
if(number[entry]>0) $("#change").append("<p>" + entry/100 + " * " + number[entry] + "</p>")
cents = cents % entry;
});
});
});