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
41 changes: 38 additions & 3 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

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


function Humanoid(humanAttrs) {
CharacterStats.call(this, humanAttrs);
this.team = humanAttrs.team;
this.weapons = humanAttrs.weapons;
this.language = humanAttrs.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
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -41,7 +76,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 +137,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
45 changes: 40 additions & 5 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. In the global scope, 'this' is binded to the Window object.
* 2. In implicit binding, the object before the . is 'this'.
* 3. With New Binding, 'this' is bound the the newly created object.
* 4. With Explicit binding, you can set the value of 'this' with call(), bind() and apply().
*
* write out a code example of each explanation above
*/

// Principle 1

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


// Principle 2

// code example for Implicit Binding
const myObj = {
greeting: 'Hello',
sayHello: function(name) {
console.log(`${this.greeting} myname is ${name}`)
}
}
myObj.sayHello('Melvin');


// Principle 3

// code example for New Binding
function hogwartsFriends() {
this.firstName = 'Ron';
this.lastName = 'Weasley';
console.log(this);
}

const bestfriend = new hogwartsFriends();


// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
function myCar() {
this.carModel = "Hyundai";
this.yearModel = 2017;
this.carMake = "Santa Fe";
console.log(this);
}

const carColor = {
color: "Red",
seats: 4,
};

myCar.apply(carColor);