Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function change(input) {
- let change = Number(input.shift());
- let count = 0;
- let coinsHundreds = Math.floor(change);
- let coins = Math.floor((change - coinsHundreds) * 100);
- while (coinsHundreds > 0 || coins > 0) {
- if (coinsHundreds >= 2) {
- coinsHundreds -= 2;
- count++;
- } else if (coinsHundreds >= 1) {
- coinsHundreds -= 1;
- count++;
- }
- if (coins >= 50) {
- coins -= 50;
- count++;
- } else if (coins >= 20) {
- coins -= 20;
- count++;
- } else if (coins >= 10) {
- coins -= 10;
- count++;
- } else if (coins >= 5) {
- coins -= 5;
- count++;
- } else if (coins >= 2) {
- coins -= 2;
- count++;
- } else if (coins >= 1) {
- coins -= 1;
- count++;
- }
- }
- console.log(count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement