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
49 changes: 44 additions & 5 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
*/


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on this prototype. All of the console logs pass and you seem to understand the material. Keep up the good work Robert.

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

GameObject.prototype.destroy = function(){
return `Object was removed from the game.`
}


/*
=== CharacterStats ===
* healthPoints
Expand All @@ -23,6 +34,20 @@
* should inherit destroy() from GameObject's prototype
*/


function CharacterStats(characterbutes){
GameObject.call(this, characterbutes);
this.healthPoints = characterbutes.healthPoints;
this.name = characterbutes.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.) ===
* team
Expand All @@ -32,7 +57,20 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/


function Humanoid(attributes) {
CharacterStats.call(this, attributes);
//GameObject.call(this, attributes);
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
}
Humanoid.prototype = Object.create(CharacterStats.prototype);

Humanoid.prototype.great = function(){
return `${this.team} says hello in ${this.language}`;
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -41,7 +79,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 @@ -91,18 +129,19 @@
],
language: 'Elvish',
});



console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
console.log(mage.name); // Bruce
console.log(swordsman.team); // The Round Table
console.log(mage.weapons); // Staff of Shamalama
console.log(archer.language); // Elvish
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
console.log(archer.great()); // 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
44 changes: 36 additions & 8 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
/* 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 Object binding - If not contained within an Object scope, 'this' has global scope.

* 2. Implicit Binding - methods/functions called with dot notation will automatically inherit parent scope with 'this' prefixed.

* 3. New bindning - wwhen used with a constructor function 'this' refers to the object it is being called on.

* 4. Explicit binding - refers to the use of call and apply, 'this' is included as the first argument and denotes the Object the calling method invokes.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
console.log(this);

// Principle 2

// code example for Implicit Binding
const speak = {
phrase : 'Hi',
deny : function(){
return this.phrase + ', ' + 'dont wanna talk rn.';
}
}

console.log(speak.deny());

// Principle 3
function makeCereal(kind){
this.Kind = kind;
this.eat = function(){
console.log(`Im in a ${this.Kind} kind of mood. Think I'll have some captain crunch.`);
}
}
const honeyNut = new makeCereal('healthy');
const captain = new makeCereal('fun');

captain.eat();

// code example for New Binding

// Principle 4

// code example for Explicit Binding
function Test(arg1, arg2){
arg1 = 0;
arg2 = 1;
return (arg2 + arg2) / (arg1 + (arg2 + 4));
}
function Test2(){
return Test.call(this, 2, 3);
}

console.log(Test2());