Advertisement
Radipc

05.Coins

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