Last active
August 29, 2015 14:26
-
-
Save rick4470/ade697d29d5165131be0 to your computer and use it in GitHub Desktop.
Coin Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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