Skip to content

completed assignment #765

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

Open
wants to merge 1 commit into
base: master
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
36 changes: 32 additions & 4 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/
function GameObject(attrs){
this.createdAt = attrs.createdAt;
this.name = attrs.name;
this.dimensions = attrs.dimensions;

}
GameObject.prototype.destroy = function(){
return `${this.name} was removed from the game.`;
}
/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats(childAttrs){
GameObject.call(this,childAttrs);
this.healthPoints = childAttrs.healthpoints;
}
CharacterStats.prototype = Object.create(GameObject.prototype);
CharacterStats.prototype.takeDamage = function(){
return `${this.name} took damage.`;
}
/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,16 +47,29 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(humanAttrs){
GameObject.call(this,humanAttrs);
CharacterStats.call(this,humanAttrs);
this.team = humanAttrs.team;
this.weapons = humanAttrs.weapons;
this.language = humanAttrs.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.
* Instances of CharacterStats should have all of the same properties as GameObject.
*/



// 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 @@ -102,7 +130,7 @@
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.
*/


// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
Expand Down
46 changes: 43 additions & 3 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 1.
Global Binding - when no other rules apply, the value of this is the Window.

* 2.
Implicit Binding - when the function is called and the object (this) is named to the left of a dot.

* 3.
New Binding - When a constructor function is used.

* 4.
*
*Explicit Binding - When a the call, apply or bind method is used to explicitly define 'this'.
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding

function sayMyName(myName) {
console.log(this);
return myName;
}
sayName("Katrina");

// Principle 2

// code example for Implicit Binding

const greetingObj = {
greeting: 'Hey yall',
sayHello: function(myName) {
console.log(`${this.greeting} my name is ${name}`);
console.log(this);
}
};
greetingObj.sayHello('Katrina');



// Principle 3

// code example for New Binding

function NiceGirl(greeter) {
this.greeting = 'Hello ';
this.greeter = greeter;
this.speak = function() {
console.log(this.greeting + this.greeter);
console.log(this);
};
}

const beyonce = new NiceGirl('Beyonce');
const kelly = new NiceGirl('Kelly');

beyonce.speak();
kelly.speak();

// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding

beyonce.speak.call(beyonce);