Skip to content

Instantly share code, notes, and snippets.

@rick4470
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save rick4470/ade697d29d5165131be0 to your computer and use it in GitHub Desktop.

Select an option

Save rick4470/ade697d29d5165131be0 to your computer and use it in GitHub Desktop.
Coin Problem
var input = 89,
quarterCount = 0,
dimeCount = 0,
nickleCount = 0,
plural = '';
if (input > 99 || input < 1) {
console.log('Invalid amount, please select a value between (1-99)');
}else{
while(input >= 25){
input -= 25;
quarterCount++;
}
while(input >= 10){
input -= 10;
dimeCount++;
}
while(input >= 5){
input -= 5;
nickleCount++;
}
console.log('Quarter'+(quarterCount > 1 ? 's': '') + ': ' + quarterCount);
console.log('Dime'+(dimeCount > 1 ? 's': '') + ': ' + dimeCount);
console.log('Nickle'+(nickleCount > 1 ? 's': '') + ': ' + nickleCount);
console.log('Pennie'+(input > 1 ? 's': '') + ': ' + input);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment