I've developed a program that calculates the denomination of bank notes (2, 5, 10, 20, etc.) you need to pay based on a number you input in the prompt.
Now, I'm looking to enhance this program by taking the input number from the first step and dividing it by a new number entered by the user in a prompt. This will help me calculate the average cost of one item.
Can someone guide me on how to achieve this?
Below is the code I've written for the initial part.
var amount = prompt("Enter amount:");
var bankNotes = [500, 200, 100, 50, 20, 10, 5, 2, 1];
var totalNotes = 0;
var output = "";
for (i = 0; i < bankNotes.length; i++) {
var x = amount / bankNotes[i];
if (x >= 1) {
var difference = Math.floor(x) * bankNotes[i];
amount = amount - difference;
totalNotes = Math.floor(x) + totalNotes;
output = output + Math.floor(x) + "x" + bankNotes[i] + ",";
console.log(output);
}
}
window.onload = function() {
document.getElementById("display").innerHTML = "Payment requires " + output;
}
<span id="display"></span>