Created
August 20, 2019 00:06
-
-
Save alacret/2d8bc76479af1871dbb887ac47d99090 to your computer and use it in GitHub Desktop.
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
| function looseChange(cents){ | |
| var coins = {'Nickels': 0, 'Pennies':0, 'Dimes':0, 'Quarters':0}; | |
| if (cents <= 0) { | |
| return coins; | |
| } | |
| cents = Math.floor(cents); | |
| coins.Quarters = Math.floor(cents / 25); | |
| var centsLeftOver = cents % 25; | |
| coins.Dimes = Math.floor(centsLeftOver / 10); | |
| centsLeftOver = centsLeftOver % 10; | |
| coins.Nickels = Math.floor(centsLeftOver / 5); | |
| coins.Pennies = centsLeftOver % 5; | |
| return coins; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment