Skip to content

update js #740

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
36 changes: 32 additions & 4 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.

In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.

At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.

Each constructor function has unique properties and methods that are defined in their block comments below:
*/


/*
=== GameObject ===
Expand All @@ -15,13 +16,30 @@
* 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(gameobj){
this.createdAt= gameobj.createdAt;
this.name= gameobj.name;
this.dimensions= gameobj.dimensions;

}
GameObject.prototype.destroy= function(){
return `${this.name} was remove from the page`;
}

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
function CharacterStats(startObj){
GameObject.call(this,startObj);
this.healthPoints= startObj.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 +50,17 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(hummanObj){
CharacterStats.call(this,hummanObj);
this.team=hummanObj.team;
this.weapons=hummanObj.weapons;
this.language=hummanObj.language;

}
Humanoid.prototype=Object.create(CharacterStats.prototype);
Humanoid.prototype.greet=function(){
return `${this.name} speak greet 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 +69,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 +130,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
38 changes: 32 additions & 6 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
/* The for principles of "this";
0/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 1. global scope is a window
* 2. impliciti bilding
* 3. new
* 4.
*
* write out a code example of each explanation above
*/

// Principle 1
function sing(singer) {

console.log(this);
return name;
}
sing();
// code example for Window Binding

// Principle 2

// Principle 2
const myCar = {
star: 'tur on',
secondStep: function( pushAc) {
console.log(`${this.star} im ready ${pushAc}`);
console.log(this);
}
};
myCar.secondStep('Go');
// code example for Implicit Binding

// Principle 3

const makeOrder = obj => {
obj.sayName = function() {
console.log(`Hello my name is ${this.name}`);
console.log(this);
};
};
const me = { name: 'Ryan' };
const you = { name: 'Freddy' };
sayNameFunc(me);
sayNameFunc(you);

// Invoke Methods on our objects
me.sayName();
you.sayName();
// code example for New Binding

// Principle 4
Expand Down