Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function puppyCare(input) {
- let index = 0;
- let food = Number(input[index]) * 1000;
- index++;
- let command = input[index];
- index++;
- let foodSum = 0;
- while (command !== "Adopted") {
- let foodDaily = Number(command);
- foodSum += foodDaily;
- command = input[index];
- index++;
- }
- if (food >= foodSum) {
- console.log(`Food is enough! Leftovers: ${food - foodSum} grams.`);
- } else {
- console.log(`Food is not enough. You need ${foodSum - food} grams more.`);
- }
- }
Add Comment
Please, Sign In to add comment