Liliana797979

viarno reshenie care of puppy

Feb 27th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function careOfPuppy(input){
  3.     let index = 0;
  4.     let food = input[index++] * 1000;
  5.     let foodEatenPerDay = input[index++];
  6.     let flag = true;
  7.  
  8.     while (foodEatenPerDay != 'Adopted') {
  9.         if(food - foodEatenPerDay >= 0){
  10.             food -= foodEatenPerDay;
  11.         }else{
  12.             food -= foodEatenPerDay;
  13.             flag = false;
  14.         }
  15.         foodEatenPerDay = input[index++];
  16.     }
  17.     if(flag){
  18.         console.log(`Food is enough! Leftovers: ${food} grams.`);
  19.     }else{
  20.         console.log(`Food is not enough. You need ${Math.abs(food)} grams more.`);
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment