Skip to content

Aasa christian #738

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 2 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
35 changes: 33 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
Each constructor function has unique properties and methods that are defined in their block comments below:
*/


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

/*
=== GameObject ===
* createdAt
Expand All @@ -16,13 +26,34 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function CharacterStats(atts){
this.healthPoints = atts.healthPoints;
GameObject.call(this, atts)
this.takeDamage = function(){
return(`${this.name} took damage`);

};
}


/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
function Humanoid(attx){
this.team = attx.team,
this.weapons = attx.weapons,
this.language = attx.language
CharacterStats.call(this, attx)
GameObject.call(this, attx)
this.greet = function(){
return (`${this.name} offers a greeting in ${this.language}.`);

};

};
/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -41,7 +72,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 +133,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
43 changes: 36 additions & 7 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Implicit Binding - this referes to what is left of the '.' when the fuction is called.
* 2. Explicit Binding - you state what the this keyword will be in the function
* 3. New Binding - when a function is call an function with the key work new in front it creats a new opject.
* 4. Window Binding - the this keyword refers to the window object
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
console.log(this);

// Principle 2

// Principle 2
// code example for Implicit Binding
const roll = function(person){
person.rollCall = function(){
console.log(this.name)
}
}
const aasa ={
name: 'Aasa',
}
roll(aasa);
aasa.rollCall();

// Principle 3

// Principle 3
// code example for New Binding

const BackPack = function (color, pockets,){
this.color = color;
this.pockets = pockets
this.thePack = (`The ${this.color} backpack has ${this.pockets} pockets.`)
};

const aasaBackPack = new BackPack('blue', 'ten')
console.log(aasaBackPack.thePack)

// Principle 4
// code example for Explicit Binding

var favTeam = function(sport, team){
console.log(`Im ${this.name} and my favorite ${sport} team is the ${team}!`);
};
var myName1 ={
name: 'Aasa',
};
var myTeam = ['football','Cowboys' ];

// code example for Explicit Binding
favTeam.apply(myName1, myTeam)