Skip to content

Myco sullivan #776

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
99 changes: 94 additions & 5 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@
* 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.name = attributes.name,
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(attributes){
GameObject.call(this, attributes),
this.healthPoints = attributes.healthPoints

}
CharacterStats.prototype = GameObject.prototype;
CharacterStats.prototype.takeDamage = function(){
return `${this.name} took damage.`

};


/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,7 +51,62 @@
* 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 = CharacterStats.prototype;
Humanoid.prototype.greet = function(){
return `${this.name} offers a greeting in ${this.language}.`
};

function Villian(attributes) {
Humanoid.call(this, attributes),
this.name = attributes.name,
this.weapons = attributes.weapons,
this.damage = attributes.damage,
this.hp = attributes.hp
}
Villian.prototype = Object.create(Humanoid);
Villian.prototype.Damage = function (char){
return `${this.name} attacks ${char.name} with a ${this.weapons} and did ${this.damage} damage to the hero! The hero now has ${char.hp-this.damage} health.`
},
Villian.prototype.Destruction = function (char1, char2){
if (this.hp <= 0){
return `${this.name} has 0 hp! ${this.name} is now unconscious.`
}else if (this.hp < 5){
return `${this.name} has ${this.hp}! They are very low on health!`
}else { return `currently ${char1.name} has ${char1.hp -char2.damage} health`}

};




function Hero(attributes){
Humanoid.call(this, attributes),
this.name = attributes.name,
this.weapons = attributes.weapons,
this.damage = attributes.damage,
this.hp = attributes.hp
}

Hero.prototype = Object.create(Villian);
let currentHealth2 = this.hp-Villian.damage;
Hero.prototype.Damage = function (char){
return `${this.name} attacks the ${char.name} with a ${this.weapons} and did ${this.damage} damage to the villian! The Villian now has ${char.hp - this.damage} health.`
};
Hero.prototype.Destruction = function (char1, char2){
if (this.hp <= 0){
return `${this.name} has 0 hp! ${this.name} is now unconscious.`
}else if (this.hp < 5){
return `${this.name} has ${this.hp}! They are very low on health!`
}else { return `currently ${char1.name} has ${char1.hp -char2.damage} health`}

};
/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -41,7 +115,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 @@ -91,7 +165,19 @@
],
language: 'Elvish',
});

const Snyder = new Villian({
name: 'Snyder the Villian',
weapons: 'Sythe of Loathing',
damage: 25,
hp: 250
});

const Stan = new Hero({
name: 'Stan the Hero',
weapons: 'Lance of Light',
damage: 30,
hp: 180
});
console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
Expand All @@ -102,7 +188,10 @@
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.
*/
console.log(Snyder.Damage(Stan));
console.log(Snyder.Destruction(Stan, Snyder));
console.log(Stan.Damage(Snyder));
console.log(Stan.Destruction(Snyder, Stan));

// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
Expand Down
41 changes: 35 additions & 6 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. window binding- this defaults to the window that you are in since it has no other reference
* 2. implicit binding- this refers to what is left of the dot
* 3. new binding- makes a new object that is based on a different object, this will refer to the new object
* 4. explicit binding- explicitly telling this what it is to point to using call apply or bind
*
* write out a code example of each explanation above
*/

// Principle 1

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

// Principle 2

// code example for Implicit Binding

const person = {
name: 'Aiden',
age: 27,
greet() {
console.log(`Hello, my name is ${this.name}`)
}
}
person.greet();
// Principle 3

// code example for New Binding
function personData (name, age, location){
this.name = name,
this.age = age,
this.location = location
};

const NewPersonData = new personData('Tyler', 32, 'South Africa');
const NewPersonData2 = new personData('Harry', 19, 'China');

console.log(`The first person that acessed this computer was ${NewPersonData.name}, age: ${NewPersonData.age}, location: ${NewPersonData.location} and the second person that acessed this computer was ${NewPersonData2.name}, age: ${NewPersonData2.age}, location: ${NewPersonData2.location} `);


// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
var person2 = {
fullName: function(city, country) {
console.log(this.firstName + " " + this.lastName + "," + city + "," + country)
}
}
var person1 = {
firstName:"John",
lastName: "Green"
}
person2.fullName.apply(person1, ["Danville", "Ky"]);