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

Submission - Attempting Bonus at a Later Date #4

Open
wants to merge 9 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
52 changes: 52 additions & 0 deletions food.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,56 @@
// 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 && this.daysToSpoil > 0){
console.log(`There are ${this.daysToSpoil} days left before ${this.name} spoils.`);
} else {
console.log(`${this.name} has spoiled. Please Discard Immediatelly!`);
}
}

aDayPasses(){
this.daysToSpoil -= 1;
this.isFresh();
}
}

const avocado = new Food("Avocado", 3);

avocado.prepare();
avocado.isFresh();
avocado.aDayPasses();


class BadFood extends Food {
constructor(name){
super(name, 20);
this.weapons = [
{ hitPoints: 3 },
{ hitPoints: 4 },
{ hitPoints: 5 }
];
}

prepare(){
console.log(`I am ${this.name} and my calories are too high to count!`)
}




}



// 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.

118 changes: 118 additions & 0 deletions tamagotchi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,122 @@
// 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(`Hello, I'm ${this.name}!`);
}

status(){
console.log(
`Status of ${this.name}:
Energy: ${this.energy}
Fullness: ${this.full}
Mood: ${this.mood}
Sick: ${this.sick ? 'Yes' : 'No'}`
);
}

eat(){
if(this.energy > 0){
console.log(`${this.name} is eating.`);
this.full += 2;
this.energy -= 1;

if (this.full > 10){
this.sick = true;
console.log(`${this.name} has become sick! :-(`);
}

this.mood += 1;
} else {
console.log(`${this.name} doesn't have enough energy to eat.`);
}
}
medicate(){
if(this.sick){
console.log(`${this.name} is taking medicine.`);
this.full = 9;
this.energy -= 3;
this.sick = false;
}else{
console.log(`${this.name} refuses to take medicine`);
this.energy -= 1;
}
}

play(){
if(this.sick){
console.log(`${this.name} is too sick to play.`);
this.mood -= 1;
this.energy -= 1;
} else if (this.mood > 9){
console.log(`${this.name} is too happy to play.`);
this.energy -= 2;
this.full -= 1;

} else if (this.energy <= 3){
console.log(`${this.name} is too tired to play.`);
this.energy -= 1;

} else {
console.log(`${this.name} is playing.`);
this.mood += 2;
this.energy -= 1;
this.full -= 1;
}
}
sleep(){
console.log(`${this.name} is sleeping. ZzzZZzz`);
this.energy += 4;
this.full -= 3;
this.mood += 1;
}

timePasses(){
if(this.sick){
this.mood -= 3;
this.full -= 2;
this.energy -= 2;
} else {
this.mood -= 2;
this.full -= 1;
this.energy -= 1;
}
}
badGuardian(){
console.log(`Oh No!${this.name} has been rehomed.`);

if(this.energy <= 0 || this.mood <= 0 || this.full <= 0){
this.rehomed = true;
}
}

checkHealth(){
if(this.sick){
console.log(`${this.name} is isck and needs medical attention.`);
} else if(this.mood <= 0){
console.log(`${this.name} is unhappy and might need more attention.`)
}
}

}

const myTamagotchi = new Tamagotchi("Lola");

myTamagotchi.greet();
myTamagotchi.status();

myTamagotchi.eat();
myTamagotchi.status();

myTamagotchi.play();
myTamagotchi.status();
// Do not edit below this line
module.exports = Tamagotchi;