TZinovieva

Guinea Pig JS Fundamentals

Feb 15th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function guineaPig(inp) {
  2.     let input = inp.map(Number);
  3.    
  4.     let food = input[0] * 1000;
  5.     let hay = input[1] * 1000;
  6.     let cover = input[2] * 1000;
  7.     let pigWeight = input[3] * 1000;
  8.  
  9.     for (let i = 1; i <= 30; i++) {
  10.         food -= 300;
  11.  
  12.         if (food <= 0 || hay <= 0 || cover <= 0) {
  13.             break;
  14.         }
  15.         if (i % 2 === 0) {
  16.             hay = hay - food * 0.05;
  17.         }
  18.         if (i % 3 === 0) {
  19.             cover -= pigWeight / 3;
  20.         }
  21.     }
  22.     if (food > 0 && hay > 0 && cover > 0) {
  23.         console.log(`Everything is fine! Puppy is happy! Food: ${(food / 1000).toFixed(2)}, Hay: ${(hay / 1000).toFixed(2)}, Cover: ${(cover / 1000).toFixed(2)}.`);
  24.     } else {
  25.         console.log(`Merry must go to the pet store!`);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment