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
37 changes: 33 additions & 4 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,30 @@
* 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(info){
this.createdAt = info.createdAt,
this.name = info.name,
this.dimensions = info.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 (stats){
GameObject.call(this,stats);
this.healthPoints = stats.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.) ===
Expand All @@ -38,10 +55,20 @@
* 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.
*/
function Humanoid (attributes){
CharacterStats.call(this,attributes);
this.team = attributes.team,
this.weapons = attributes.weapons,
this.language = attributes.language
}
Humanoid.prototype = Object.create(CharacterStats.prototype);
Humanoid.prototype.greet = function(){
return `${this.name} offers a greeting in ${this.language}.`
}

// 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,9 +129,11 @@
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.
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
// * Create two new objects, one a villain and one a hero and fight it out with methods!
// * Create two new objects, one a villain and one a hero and fight it out with methods!

//NOT TODAY SATAN!
72 changes: 64 additions & 8 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,82 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Window/Global binding occurs by default if none othe other cases apply to the 'this' keyword.
* 2. Implicit Binding is when a function is ivoked and there is a dot to the left of it, what is in front of that dot gives the context of what 'this' is.
* 3. New Binding is when the 'new' keyword is used to create a new object; in these cases 'this' points specifically to it.
* 4. Explicit Binding is when you are stating that 'this' points to a specific value bu using call, apply, or bind.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
function opp(){
console.log (`You down with O.P.P.? ${this.answer}...yea it's probaly best to not answer that.`);
}
opp();
const answer = 'Yea you know me!';

// Principle 2

// code example for Implicit Binding
let daGreatest = {
name: 'Muhammad Ali',
occupation: 'boxer',
hometown: 'Louisville, KY',
saying: 'float like a butterfly and sting like a bee',
rememberedAs: function(){
console.log(`${this.name} is the greatest ${this.occupation} there has been and ever will be. He could ${this.saying}; rumble young man rumble!`)
}
}
daGreatest.rememberedAs();

// Principle 3

// code example for New Binding
function bond(){
console.log(`${this.name} is the true 007.`);
}

let goldfinger = {
name: 'Sean Connery',
movies: 7
}

let skyfall = {
name: 'Daniel Craig',
movies: 5
}

let octopussy = {
name: 'Roger Moore',
movies: 7
}

bond.call(skyfall);

// Principle 4
// code example for Explicit Binding
function Throne(heir){
this.name = heir.name,
this.house = heir.house
}

Throne.prototype.claim = function(){
return `I am ${this.name} of House ${this.house} and I am the rightful ruler of the seven Kingdoms!`;
}

const motherOfDragons = new Throne ({
name: 'Daenerys',
house: 'Targaryen',
});

const iDontWantIt = new Throne ({
name: 'John',
house: '...I am a bastard...no I am a Stark...fine I will be a Targaryen',
});

const crazyAF = new Throne ({
name: 'Cersai',
house: 'Lannister',
});

// code example for Explicit Binding
console.log(motherOfDragons.claim());