-
Notifications
You must be signed in to change notification settings - Fork 0
Nathan culver #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,29 @@ | |
| * dimensions (These represent the character's size in the video game) | ||
| * destroy() // prototype method -> returns the string: 'Object 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 | ||
| * name | ||
| * takeDamage() // prototype method -> returns the string '<object name> took damage.' | ||
| * should inherit destroy() from GameObject's prototype | ||
| */ | ||
| function CharacterStats (Attributes) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job |
||
| GameObject.call(this, Attributes); | ||
| this.hp = Attributes.hp; | ||
| this.name = Attributes.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 | ||
|
|
@@ -32,7 +46,17 @@ | |
| * should inherit destroy() from GameObject through CharacterStats | ||
| * should inherit takeDamage() from CharacterStats | ||
| */ | ||
|
|
||
| function Humanoid (Attributes) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job |
||
| CharacterStats.call(this, Attributes); | ||
| this.faction = Attributes.faction; | ||
| 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. | ||
|
|
@@ -41,7 +65,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: { | ||
|
|
@@ -102,7 +126,7 @@ | |
| console.log(archer.greet()); // Lilith offers a greeting in Elvish. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happen to the swordsman and archer??? |
||
| console.log(mage.takeDamage()); // Bruce took damage. | ||
| console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. several of these are not working because you're missing code. |
||
| */ | ||
|
|
||
|
|
||
| // Stretch task: | ||
| // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| /* The for principles of "this"; | ||
| * in your own words. explain the four principle for the "this" keyword below. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very good! short and concise answers that are correct and to the point. Love it. |
||
| * | ||
| * 1. | ||
| * 2. | ||
| * 3. | ||
| * 4. | ||
| * 1. Global: "this" points to the window object. | ||
| * 2. Implicit: "this" points to the object before the dot. | ||
| * 3. New: "this" is set within a constructor function and points to the created object. | ||
| * 4. Explicit: "this" points to instance that JavaScript’s call/apply method is used. | ||
| * | ||
| * write out a code example of each explanation above | ||
| */ | ||
|
|
@@ -13,14 +13,83 @@ | |
|
|
||
| // code example for Window Binding | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job |
||
|
|
||
| let sayAge = function() { | ||
| console.log(this.name); | ||
| console.log(this.age); | ||
| }; | ||
|
|
||
| let me = { | ||
| name: "Nathan", | ||
| age: 30 | ||
| }; | ||
|
|
||
| sayAge(); | ||
|
|
||
| // Principle 2 | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job, I like that you took the time to make multiple examples. |
||
| // code example for Implicit Binding | ||
|
|
||
| let Person = function(name, age) { | ||
| return { | ||
| name: name, | ||
| age: age, | ||
| sayName: function() { | ||
| console.log(`Hello, my name is ${this.name}.`); | ||
| }, | ||
| josh: { | ||
| name: "Josh", | ||
| age: age, | ||
| sayName: function() { | ||
| console.log(`I'm ${this.name}.`); | ||
| } | ||
| }, | ||
| steven: { | ||
| name: "Steven", | ||
| age: age, | ||
| sayName: function() { | ||
| console.log(`Nice to meet you two. My name is ${this.name}.`); | ||
| } | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| let nathan = Person("Nathan", 30); | ||
| nathan.sayName(); | ||
| nathan.josh.sayName(); | ||
| nathan.steven.sayName(); | ||
|
|
||
| // Principle 3 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job |
||
|
|
||
| // code example for New Binding | ||
|
|
||
| let Person = function(name, age, race) { | ||
| this.name = name; | ||
| this.age = age; | ||
| this.race = race; | ||
| }; | ||
|
|
||
| let mike = new Person("Mike", "40", "White"); | ||
|
|
||
| console.log(mike); | ||
|
|
||
| // Principle 4 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job |
||
|
|
||
| // code example for Explicit Binding | ||
| // code example for Explicit Binding | ||
|
|
||
| let sayName = function(game1, game2, game3) { | ||
| console.log(`Hello. My name is ${this.name}. I love playing ${game1}, ${game2}, and ${game3}`); | ||
| }; | ||
|
|
||
| let nathan = { | ||
| name: "Nathan", | ||
| age: 30 | ||
| }; | ||
|
|
||
| let games = ["MTGA", "EU4", "Ark"]; | ||
|
|
||
| sayName.call(nathan, games[0], games[1], games[2]) | ||
|
|
||
| sayName.apply(nathan, games) | ||
|
|
||
| let newFn = sayName.bind(nathan, games[0], games[1], games[2]) | ||
| newFn(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job here