Skip to content

Jarrod skahill #766

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 3 commits 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
35 changes: 33 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,32 @@
* 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 (mainat) {
this.createdAt = mainat.createdAt;
this.dimensions = mainat.dimensions;
this.name = mainat.name;
};
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(mainat) {
GameObject.call(this, mainat);
this.healthPoints = mainat.healthPoints;
this.name = mainat.name;
}
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 @@ -32,6 +51,18 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/
function Humanoid(mainat) {
CharacterStats.call(this, mainat);
this.team = mainat.team;
this.weapons = mainat.weapons;
this.language = mainat.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
Expand All @@ -41,7 +72,7 @@

// 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 +133,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
34 changes: 33 additions & 1 deletion assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 1. Window Binding is when no other rules are present the "this" keyword will automatically implement window object, if strict mode is active it will default undefined instead.
* 2.
* 3.
* 4.
Expand All @@ -10,17 +10,49 @@
*/

// Principle 1
function hotWheel(monster){
console.log(`I use to love` + `${this.monster}` + ` trucks`);
return monster;

}
hotWheel(this);

// code example for Window Binding

// Principle 2
let jay = {
name: "Jarrod",
says: "what's up guys!",
jaySays: function (){
console.log(this.says)
}
}

jay.jaySays();

// code example for Implicit Binding

// Principle 3
function fastCar(brz){
this.thing = brz;
}

let Car = new fastCar('brz goes 0-60 in 6.2 sec');
console.log(Car.thing);

// code example for New Binding

// Principle 4
function car(){
console.log(this.fast);
}

let wrx = {
brand: "subaru",
fast: "0-60 in 5.5 seconds"
}

car.call(wrx)


// code example for Explicit Binding