Advertisement
Guest User

Untitled

a guest
Nov 7th, 2019
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function change(input) {
  2. let change = Number(input.shift());
  3. let count = 0;
  4. let coinsHundreds = Math.floor(change);
  5. let coins = Math.floor((change - coinsHundreds) * 100);
  6.  
  7. while (coinsHundreds > 0 || coins > 0) {
  8. if (coinsHundreds >= 2) {
  9. coinsHundreds -= 2;
  10. count++;
  11. } else if (coinsHundreds >= 1) {
  12. coinsHundreds -= 1;
  13. count++;
  14. }
  15.  
  16. if (coins >= 50) {
  17. coins -= 50;
  18. count++;
  19. } else if (coins >= 20) {
  20. coins -= 20;
  21. count++;
  22. } else if (coins >= 10) {
  23. coins -= 10;
  24. count++;
  25. } else if (coins >= 5) {
  26. coins -= 5;
  27. count++;
  28. } else if (coins >= 2) {
  29. coins -= 2;
  30. count++;
  31. } else if (coins >= 1) {
  32. coins -= 1;
  33. count++;
  34. }
  35. }
  36.  
  37. console.log(count);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement