Answers for "function change(cash)"

0

function change(cash)

function giveChange(amount) {
    var ch = { two:0, five:0, ten:0 };

    if ( amount < 2 || amount == 3 ) return;

    if ( amount % 2 ) {
        amount -= 5;
        ch.five ++;
    }
  
    ch.ten = Math.floor(amount/10);

    ch.two = (amount % 10)/2;

    return ch;
}

console.log(giveChange(12));
console.log(giveChange(27));
console.log(giveChange(33));
Posted by: Guest on February-29-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language