Skip to content
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

Jesus Rodriguez #745

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

function GameObject(gameProp) {
this.createdAt = gameProp.createdAt,
this.dimensions = gameProp.dimensions
}
GameObject.prototype.destroy = function () {
return `${this.name} was removed from the database.`;
}

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats(charProp) {
GameObject.call(this, charProp)
this.healthPoints = charProp.healthPoints,
this.name = charProp.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
* weapons
* language
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/


function Humanoid(humanProp) {
CharacterStats.call(this, humanProp)
this.team = humanProp.team;
this.weapons = humanProp.weapons;
this.language = humanProp.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 +73,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 +134,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
22 changes: 18 additions & 4 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Globa/Window binding object: When in the global scope, the value of “this” will be the window/console Object
* 2. Implicit Binding: Whenever a function is called by a preceding dot, the object before that dot is this.
* 3. New Binding: Whenever a constructor function is used, this refers to the specific instance of the object that is created and returned by the constructor function.
* 4. Explicit Binding: Whenever JavaScript’s call or apply method is used, this is explicitly defined.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
function sayCity(city) {
return city;
}
sayCity("Miami-Beach");



// Principle 2

// code example for Implicit Binding
const myGreeting = {
greeting: 'Hello',
sayHi: function(name) {
console.log(`${this.greeting} my name is ${name}`);

}
};
myGreeting.sayHi("Jesus");

// Principle 3

Expand Down