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

Completes OOP Lab. Passes all tests! #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion food.js
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions tamagotchi.js
Original file line number Diff line number Diff line change
@@ -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;