Advertisement
Spocoman

Cat Shelter

Jan 9th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function catShelter(input) {
  2.  
  3.     let food = Number(input.shift()) * 1000;
  4.     let command = input.shift();
  5.  
  6.     while (command !== "Adopted") {
  7.         food -= Number(command);
  8.         command = input.shift();
  9.     }
  10.  
  11.     if (food >= 0) {
  12.         console.log(`Food is enough! Leftovers: ${food} grams.`);
  13.     } else {
  14.         console.log(`Food is not enough. You need ${Math.abs(food)} grams more.`);
  15.     }
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement