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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ This challenge focuses on using the `this` keyword as well as getting comfortabl

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [x] Create a forked copy of this project.
* [x] Add your project manager as collaborator on Github.
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.
* [x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [x] Add your project manager as a reviewer on the pull-request
* [x] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Set Up

Expand Down
43 changes: 36 additions & 7 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,31 @@
* 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(properties) {
this.createdAt = properties.createdAt;
this.name = properties.name;
this.dimensions = properties.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) {
this.healthPoints = stats.healthPoints;

GameObject.call(this, stats)
}
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 +49,19 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(attributes) {
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;

CharacterStats.call(this, attributes)
}

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.
Expand All @@ -41,7 +70,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 @@ -96,13 +125,13 @@
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(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(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
30 changes: 20 additions & 10 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
/* The for principles of "this";
/* The four principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Principle 1: Global `this` usage refers to window Object. (Global Object Binding)
* 2. Princible 2: The object preceding the `.` is referenced as `this`. (Implicit Binding)
* 3. Principel 3: Using a constructor, the object that is returned is refered to `this`. (New Binding)
* 4. When using call, `this` is explicitly defined. (Explicit Binding)
*
* write out a code example of each explanation above
*/

// Principle 1

function globalScope () { console.log(this) }; globalScope();
// code example for Window Binding

// Principle 2

const myObj = { name: 'Dajuan', age: 35, gender: 'Male', greeting: function(name){ console.log(`Hi ${name}, are you
older than ${this.age}? Are you a ${this.gender}?`)} }; myObj.greeting('Team Lead');
// code example for Implicit Binding

// Principle 3

function RomanNumeral(numeral) {
this.X = 10,
this.M = 1000,
this.V = 5,
this.L = 50,

this.value = function(){console.log(this)}
}
const I = new RomanNumeral(1);
const D = new RomanNumeral(10);
// code example for New Binding

// Principle 4

// code example for Explicit Binding
I.value.apply(D)
// code example for Explicit Binding