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
25 changes: 22 additions & 3 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@

Each constructor function has unique properties and methods that are defined in their block comments below:
*/

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

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

function CharacterStats(charAttributes){
GameObject.call(this,charAttributes);
this.hp = charAttributes.hp;
this.name = charAttributes.name;
this.healthPoints = charAttributes.healthPoints;
}

CharacterStats.prototype = object.create(GameObject.prototype);
CharacterStats.prototype.takeDamage = function (){
return `${this.name} took damage`;
}
/*
=== GameObject ===
* createdAt
Expand Down Expand Up @@ -41,7 +60,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 +121,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
4 changes: 2 additions & 2 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 1. The 'this' keyword will have a value of the window or console object when in the Global Scope.
* 2. If a function is called by a preceding dot, 'this' is the object before the dot
* 3.
* 4.
*
Expand Down