Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function guineaPig(array) {
- let gram = 1000;
- let month = 30; //days
- let copyArray = array.slice();
- let quantityFood = copyArray.shift() * gram;
- let hay = Number(copyArray.shift()) * gram; // сено
- let cover = Number(copyArray.shift()) * gram;
- let weight = Number(copyArray.shift()) * gram;
- let isEnough = true;
- for (let day = 1; day <= month; day++) {
- quantityFood -= 300;
- if (quantityFood <= 0 || hay <= 0 || cover <= 0) {
- isEnough = false;
- break;
- }
- if (day % 2 === 0) {
- hay -= quantityFood * 0.05;
- }
- if (day % 3 === 0) {
- cover -= weight / 3;
- }
- }
- if (!isEnough) {
- console.log(`Merry must go to the pet store!`);
- } else {
- console.log(
- `Everything is fine! Puppy is happy! Food: ${(
- quantityFood / gram
- ).toFixed(2)}, Hay: ${(hay / gram).toFixed(2)}, Cover: ${(
- cover / gram
- ).toFixed(2)}.`
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement