eternalmeg

careOfPuppyRepFB

May 18th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CareDog(input) {
  2.     let foodBegin = Number(input[0]);
  3.     index = 1;
  4.     let command = Number(input[index]);
  5.     index++;
  6.     sumFood = 0;
  7.  
  8.     let foodBeginGram = foodBegin * 1000;
  9.  
  10.     while (command !== "Adopted") {
  11.         let currentFood = Number(command);
  12.         sumFood += currentFood;
  13.  
  14.        
  15.  
  16.         command = input[index];
  17.         index++;
  18.     }
  19.     if (sumFood > foodBeginGram) {
  20.         let diff = Math.abs(sumFood - foodBeginGram);
  21.         console.log(`Food is not enough. You need ${diff} grams more.`);
  22.    
  23.     }else {
  24.         let diff = Math.abs(sumFood - foodBeginGram);
  25.         console.log(`Food is enough! Leftovers: ${diff} grams.`);
  26.     }
  27.  
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment