Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function guineaPig(input) {
- let index = 0;
- let food = Number(input[index]) * 1000;
- index++;
- let hay = Number(input[index]) * 1000;
- index++;
- let cover = Number(input[index]) * 1000;
- index++;
- let weight = Number(input[index]) * 1000;
- index++;
- let dayCounter = 0;
- let goodsEnough = true;
- while (dayCounter < 30) {
- dayCounter++;
- if (food - 300 < 0) {
- goodsEnough = false;
- console.log("Merry must go to the pet store!");
- break;
- } else {
- food -= 300;
- }
- if (dayCounter % 2 === 0) {
- let hayNeeded = food * 0.05;
- if (hay - hayNeeded < 0) {
- goodsEnough = false;
- console.log("Merry must go to the pet store!");
- break;
- } else {
- hay -= hayNeeded;
- }
- }
- if (dayCounter % 3 === 0) {
- let coverNeeded = weight / 3;
- if (cover - coverNeeded < 0) {
- goodsEnough = false;
- console.log("Merry must go to the pet store!");
- break;
- } else {
- cover -= coverNeeded;
- }
- }
- }
- if (goodsEnough) {
- console.log(`Everything is fine! Puppy is happy! Food: ${(food / 1000).toFixed(2)}, Hay: ${(hay / 1000).toFixed(2)}, Cover: ${(cover / 1000).toFixed(2)}.`);
- }
- }
- guineaPig(["10",
- "5",
- "5.2",
- "1"]);
- guineaPig(["1",
- "1.5",
- "3",
- "1.5"
- ]);
- guineaPig(["9",
- "5",
- "5.2",
- "1"]);
Add Comment
Please, Sign In to add comment