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