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