-Enigmos-

puppyCare.js

Oct 31st, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function puppyCare(input) {
  2.     let index = 0;
  3.     let food = Number(input[index]) * 1000;
  4.     index++;
  5.     let command = input[index];
  6.     index++;
  7.     let foodSum = 0;
  8.  
  9.     while (command !== "Adopted") {
  10.         let foodDaily = Number(command);
  11.         foodSum += foodDaily;
  12.  
  13.         command = input[index];
  14.         index++;
  15.     }
  16.    
  17.     if (food >= foodSum) {
  18.         console.log(`Food is enough! Leftovers: ${food - foodSum} grams.`);
  19.     } else {
  20.         console.log(`Food is not enough. You need ${foodSum - food} grams more.`);
  21.     }
  22. }
Add Comment
Please, Sign In to add comment