diff --git a/food.js b/food.js index 7fd40ce..c9913b2 100644 --- a/food.js +++ b/food.js @@ -1,4 +1,24 @@ // Create class below - +class Food { + constructor(name, daysToSpoil, fresh = true) { + this.name = name; + this.daysToSpoil = daysToSpoil; + this.fresh = fresh + } + prepare() { + console.log(`${this.name} is being prepared`) + } + isFresh() { + if(this.fresh == false || this.daysToSpoil <= 0) { + console.log(`${this.name} has spoiled.`) + } else { + console.log(`There are ${this.daysToSpoil} days left before ${this.name} spoils.`) + } + } + aDayPasses() { + this.daysToSpoil-- + this.isFresh(); + } +} // Do not edit below this line module.exports = Food; diff --git a/package-lock.json b/package-lock.json index 5ba74ba..4636f32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "oop-fruits-pets-lab-solution", "version": "1.0.0", "license": "ISC", "dependencies": { diff --git a/tamagotchi.js b/tamagotchi.js index 9bd9465..95de369 100644 --- a/tamagotchi.js +++ b/tamagotchi.js @@ -1,4 +1,94 @@ // Create class below +class Tamagotchi { + constructor( + name, + energy = 9, + full = 8, + mood = 6, + sick = false, + rehomed = false + ) { + this.name = name; + this.energy = energy; + this.full = full; + this.mood = mood; + this.sick = sick; + this.rehomed = rehomed; + } + greet() { + console.log(`Hey There!, I'm ${this.name}`); + } + status() { + console.log(`My mood is: ${this.mood}!\n I am this full: ${this.full}!\n + My energy is: ${this.energy}!\n`) + if (this.sick === true) + console.log("I am sick\n") + else + console.log("I am not sick\n") + } + eat() { + this.full += 2; + this.energy--; + if(this.full >10) + this.sick = true; + } + medicate() { + if (this.sick === true) { + this.full = 9; + this.energy -=3; + this.sick= false; + } + else { + this.energy-- + console.log("refusal to take medicine") + } + } + play() { + if(this.sick === true) { + this.mood-- + this.energy-- + } + else if(this.mood>9) { + this.energy -=2 + this.full-- + } + else if(this.energy<=3) { + this.energy-- + console.log("I am too tired to play") + } + else { + this.mood+=2 + this.energy-- + this.full-- + } + } + sleep() { + this.energy+=4; + this.full-=3 + } + timePasses() { + if(this.sick !== true) { + this.mood-=2 + this.full-- + this.energy-- + } + else if(this.sick == true) { + this.mood-=3; + this.full-=2 + this.energy-=2 + } + } + badGuardian() { + console.log(`${this.name} has been rehomed`) + if (this.energy <= 0) + this.rehomed = true + if (this.mood <= 0) + this.rehomed = true + if (this.full <= true) + this.rehomed = true + } +} + // Do not edit below this line module.exports = Tamagotchi;