Creating change with the smallest number of coins This is a basic algorithm that creates change with the smallest number of coins. How can this be better written? It works perfectly, but I just imagine there is a cleaner and shorter version of this.

const generateCoinChange = cents =&gt; {
    let quarter = 0;
    let dime = 0;
    let nickel = 0;
    let penny = 0;
    let remainingChange = cents;

    while (remainingChange &gt;= 25) {
        remainingChange -= 25;
        quarter++;
    }
    while (remainingChange &gt;= 10) {
        remainingChange -= 10;
        dime++;
    }
    while (remainingChange &gt;= 5) {
        remainingChange -= 5;
        nickel++;
    }
    while (remainingChange &gt; 0) {
        remainingChange -= 1;
        penny++;
    }
    console.log(`Quarters: ${quarter}, Dimes: ${dime}, Nickels: ${nickel}, Pennies: ${penny}`)
};
generateCoinChange(94);
generateCoinChange(100);
generateCoinChange(23);
So .. you're repeatedly subtracting a number from another number, and seeing how many times you can do that without going negative? There's a word for that: division.

EDIT: Since you want the actual code

const generateCoinChange = cents =&gt; {
    let quarter = Math.floor(cents/25);
    cents -= 25*quarter
    let dime = Math.floor(cents/10);
    cents -= 10*dime
    let nickel = Math.floor(cents/5);
    cents -= 5*nickel
    let penny = cents;
    console.log(`Quarters: ${quarter}, Dimes: ${dime}, Nickels: ${nickel},Pennies: ${penny}`)
};


You can also do:

 const generateCoinChange = cents =&gt; {
     let counts = [0,0,0,cents]
     let denominations = [25,10,5]
     for (i=0,i&lt;3,i++){
         counts[i] = Math.floor(counts[3]/denominations[i])
         counts[3] -= counts[i]*denominations[i]
     }
 console.log(`Quarters: ${denominations[0]}, Dimes: ${denominations[1]}, Nickels: ${denominations[2]}, Pennies: ${denominations[3]}`)
 };