Pet
What family would be complete without a pet?
Completed Code
function Pet(firstName, lastName, gender, age, birthday, animal, breed, color) {
Person.call(this, firstName, lastName, gender, age, birthday)
this.animal = animal;
this.breed = breed;
this.color = color;
this.good = function () {
if (this.pronoun().toLowerCase() == "he") {
return "boy";
} else if (this.pronoun().toLowerCase() == "she") {
return "girl";
} else {
return this.animal;
}
}
}
Pet.prototype = Object.create(Person.prototype);
Pet.prototype.constructor = Pet;
Pet.prototype.description = function () {
return ("My " + this.animal + ", " + this.firstName + ", is the world's greatest " + this.breed + ".");
};
Pet.prototype.bday = function () {
return ("Our " + this.color + " " + this.breed + " turns " + this.nextYear + " on " + this.birthday + ".");
};
Pet.prototype.praise = function () {
return (this.pronoun() + " is/are " + "such a good " + this.good() + "!");
};
var pet1 = new Pet('Bon-Bon', 'Jovi', 'female', 3, 'February 14', 'dog', 'Border Collie', 'black and white');
console.log(pet1);
console.log(pet1.description());
console.log(pet1.bday());
console.log(pet1.praise());Output
Explanation
New Properties
animal- is your pet a dog, a cat, fish, horse, etc?breed- is your dog a boxer, your cat a siamese?color- what color is/are your pets fur, scales, feathers, etc?good()- a function that we'll use to output a noun based on the gender pronoun.
New Functions
description()- displaysanimal,firstName, andbreed.bday()- displayscolor,breed, as well asnextYearandbirthdaypraise()- displayspronounand the result ofgood().
Last updated