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
3 changes: 2 additions & 1 deletion classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
// Also give it a method "Speak", which says "Hello, My name is + name + and I'm + age + years old. I love + Hobby"


// Extend Person class and create one class for each member of your family.
// Extend Person class and create one class for each member of your family.
//
33 changes: 30 additions & 3 deletions prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@
* 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(attributes) {
this.createdAt = attributes.createdAt;
this.dimensions = attributes.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(attr) {
GameObject.call(this, attr)
this.name = attr.name;
this.healthPoints = attr.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.) ===
Expand All @@ -32,7 +48,17 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(attributes) {
CharacterStats.call(this, attributes)
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.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 Down Expand Up @@ -107,4 +133,5 @@
// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
// * Create two new objects, one a villain and one a hero and fight it out with methods!
// * Create two new objects, one a villain and one a hero and fight it out with methods!

61 changes: 48 additions & 13 deletions 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.
*
* write out a code example of each explanation above
*/
// * The for principles of "this";
// * in your own words. explain the four principle for the "this" keyword below.

// * 1
// * 2
// * 3
// * 4

// * write out a code example of each explanation above


// Principle 1

// code example for Window Binding
function dayOfTheWeek(date) {
console.log(this)
}
dayOfTheWeek("Wednesday");

// Principle 2

// code example for Implicit Binding

const food = {
name: "Cheeseburger",
ingredients: ["Cheese", " Meat", " Lettuce", " Bacon"],
howToMake: function() {
console.log(`A ${this.name} has ${this.ingredients}`);
}
}

food.howToMake();
// Principle 3

// code example for New Binding

function BestJSFramework(framework) {
this.framework = framework;
this.end = "is the best framework, period!"
this.iAmBest = function() {
console.log(`${this.framework} ${this.end}`)
}
}

const angular = new BestJSFramework("Angular");
const react = new BestJSFramework("React");

angular.iAmBest();
react.iAmBest();
// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
const city = {
name: "New York City"
}

const neighborhoods = ["Upper West Side", "East Village", "Lower Manhattan"];

function neighborhoodsInCity(neighborhoods) {
console.log(`${neighborhoods} are located in ${this.name}`);
}

neighborhoodsInCity.call(city, neighborhoods);