Can you please help me improve my function that displays the number of coins corresponding to a certain value? For example, an input of 56 should return [25, 25, 5, 1].
I am facing two challenges: 1) How can I display multiple instances of the same coin in the array (I suspect there may be an issue with the Math function below)? 2) Is it possible to remove any 0s from the array?
Any assistance would be greatly appreciated.
function getCoins(){
let coins = [25, 10, 5, 1];
amount = prompt("Enter an amount to convert into coins");
coinAmount = "";
for (i = 0; i < coins.length; i++){
if (amount % coins[i] >= 0){
coinAmount += coins[i] * (Math.floor(amount/coins[i])) + ",";
amount = amount % coins[i];
console.log(coinAmount)
}
}
}
getCoins()