Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 async #289

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
39 changes: 39 additions & 0 deletions homeworks/olha.dobrodii_olgadobrodii/4-objects/objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const tamagochi = {
maxHealth: 10,
maxHappiness: 10,
maxBellyful: 10,
growUp() {
this.health += 1;
this.happiness += 1;
this.bellyfull += 1;
},
reduction() {
this.health -= 1;
this.happiness -= 1;
this.bellyfull -= 1;
},
playWithMe() {
this.health -= 2;
this.happiness += 1;
this.bellyfull -= 3;
},
feedMe() {
this.health += 2;
this.happiness += 1;
this.bellyfull += 3;
},
};
tamagochi.checkLife = function () {
if ((this.health) <= 0
|| (this.happiness) <= 0
|| (this.bellyful) <= 0) {
return false;
}
return true;
};
tamagochi.showMassage = function () {
if (this.checkLife() === false) {
return 'happy pet';
}
return 'sorry, you pet died';
};
58 changes: 58 additions & 0 deletions homeworks/olha.dobrodii_olgadobrodii/6-async/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const tamagochi = new Tamagochi();
function Tamagochi() {
this.intervalId = setInterval(this.timer, 500);
this.timer = function() {
const arr_tamagochi = [this.growUp, this.reduction, this.playWithMe, this.feedMe];
Math.floor(Math.random() * 10)
if(this.health < 1
|| this.happiness < 1
|| this.happiness < 1
|| this.bellyfull < 1) {
arr_tamagochi = true;
this.showMassage();
} else {
tamagochi_random = false;
this.showMassage();
}
}
this.growUp = function() {
this.health += 1;
this.happiness += 1;
this.bellyfull += 1;

this.showMassage();
},
this.reduction = function() {
this.health -= 1;
this.happiness -= 1;
this.bellyfull -= 1;
this.showMassage();
},
this.playWithMe = function () {
this.health += 2;
this.happiness += 1;
this.bellyfull += 3;
this.showMassage();
},

this.feedMe = function () {
this.health += 2;
this.happiness += 1;
this.bellyfull += 3;
this.showMassage();
}
tamagochi.checkLife = function () {
if ((this.health) <= 0
|| (this.happiness) <= 0
|| (this.bellyful) <= 0) {
return false;
}
return true;
};
tamagochi.showMassage = function () {
if (this.checkLife() === false) {
return 'happy pet';
}
return 'sorry, you pet died';
}
};