Skip to content
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
61 changes: 56 additions & 5 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- When pooping, the stomach should empty.
*/


function Person(attr) {

this.name = attr.name;
Expand Down Expand Up @@ -76,6 +77,9 @@ function Person(attr) {
}
// const jay = new Person({name:"jj", age:23});




/*
TASK 2

Expand All @@ -88,6 +92,7 @@ function Person(attr) {
- A repaired car can be driven again.
*/


function Car(attr) {

this.model = attr.model;
Expand Down Expand Up @@ -115,6 +120,8 @@ Car.prototype.repair = function repairCar() {
// const bmw = new Car({model:"X6", make:"BMW" });




/*
TASK 3

Expand All @@ -139,8 +146,10 @@ Baby.prototype.playPlay = function playing() {
Baby.prototype.cryCry = function crying() {
return this.play = "Baby JJ is not cute when crying"
};
// const babyJay = new Baby({ name: "baby jj", age: "8 months", play: "I want to play!", cry: "Weeemmmm weeemmmmm" });



const babyJay = new Baby({ name: "baby jj", age: "8 months", play: "I want to play!", cry: "Weeemmmm weeemmmmm" });

/*
TASK 4
Expand Down Expand Up @@ -182,9 +191,10 @@ const jj = new Department({
'gender': 'male',
'pass': 'yes I passed it!'
});
// jj.intro();
// jj.celebrate();


jj.intro();
jj.celebrate();


/*
Expand All @@ -206,13 +216,38 @@ jj.celebrate();
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function GameObject(gameAttr) {
this.createdAt = gameAttr.createdAt;
this.name = gameAttr.name
this.dimensions = gameAttr.dimensions
}

GameObject.prototype.destroy = function() {
return `${this.name} was removed from the game.`;
}
// const jjj = new GameObject({createdAt: "eeee", name: "kkkk", dimensions: 833});


/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats(charAttr) {
GameObject.call(this, charAttr);
this.healthPoints = charAttr.healthPoints;
}

CharacterStats.prototype = Object.create(GameObject.prototype);

CharacterStats.prototype.takeDamage = function() {
return `${this.name} took damage`;
}
// const jj = new CharacterStats({createdAt: "rrr", name: "wfvvvev", dimensions: 33, healthPoints: 55});


/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -223,6 +258,22 @@ jj.celebrate();
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(hAttr) {
CharacterStats.call(this, hAttr);
this.name = hAttr.name;
this.team = hAttr.team;
this.weapons = hAttr.weapons;
this.language = hAttr.language;
}

Humanoid.prototype = Object.create(CharacterStats.prototype);

Humanoid.prototype.greet = function() {
return `${this.name} offers a greeting in ${this.language}`;
}



/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -231,7 +282,7 @@ jj.celebrate();

// Test you work by un-commenting these 3 objects and the list of console logs below:

/*

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -289,4 +340,4 @@ jj.celebrate();
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
console.log(mage.takeDamage()); // Bruce took damage.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
*/

10 changes: 5 additions & 5 deletions assignments/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// code example for Window Binding

function sayName(name) {
console.log(this);
// console.log(this);
return name;
}
sayName("D'Artagnan");
Expand All @@ -40,8 +40,8 @@ function sayName(name) {
const myObj = {
greeting: 'Hello',
sayHello: function(name) {
console.log(`${this.greeting} my name is ${name}`);
console.log(this);
// console.log(`${this.greeting} my name is ${name}`);
// console.log(this);
}
};
myObj.sayHello('Ryan');
Expand All @@ -56,8 +56,8 @@ function CordialPerson(greeter) {
this.greeting = 'Hello ';
this.greeter = greeter;
this.speak = function() {
console.log(this.greeting + this.greeter);
console.log(this);
// console.log(this.greeting + this.greeter);
// console.log(this);
};
}

Expand Down