Skip to content

Jake johnson #714

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

/*
/*
=== GameObject ===
* createdAt
* name
* 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(object){
this.createdAt = object.createdAt;
this.name = object.name;
this.dimensions = object.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(stats) {
GameObject.call(this, stats);

this.healthPoints = stats.healthPoints;
this.name = stats.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.) ===
Expand All @@ -32,7 +54,18 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/


function Humanoid(humanoid) {
CharacterStats.call(this, humanoid);
this.team = humanoid.team;
this.weapons = humanoid.weapons;
this.language = humanoid.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 +74,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,9 +135,91 @@
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.
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
// * Create two new objects, one a villain and one a hero and fight it out with methods!
// * Create two new objects, one a villain and one a hero and fight it out with methods!

function Hero(info){
Humanoid.call(this, info);
}

Hero.prototype = Object.create(Humanoid.prototype);
Hero.prototype.attack = function(villain) {
if (this.healthPoints <= 0) {
return(`${this.name} is dead.`);
}
if (villain.healthPoints > 0 ) {
villain.healthPoints -= 5;
if (villain.healthPoints <= 0 ) {
return(`${this.name} attacks their opponent, 5 damage dealt. \n ${villain.destroy()}`);
}
return (`${this.name} attacks their opponent, 5 damage dealt. \n ${villain.name} - ${villain.healthPoints}`);
}
else {
return (`${villain.name} has already died.`);
}
}

function Villain(info){
Humanoid.call(this, info);
}

Villain.prototype = Object.create(Humanoid.prototype);

Villain.prototype.stab = function(hero) {
if (this.healthPoints <= 0) {
return(`${this.name} is dead.`);
}
if (hero.healthPoints > 0 ) {
hero.healthPoints -= 5;
if (hero.healthPoints <= 0 ) {
return(`${this.name} attacks their opponent, 5 damage dealt. \n ${hero.destroy()}`);
}
return (`${this.name} attacks their opponent, 5 damage dealt. \n ${hero.name} - ${hero.healthPoints}`);
}
else {
return (`${hero.name} has already died.`);
}
}

const yasuo = new Hero({
createdAt: new Date(),
dimensions: {
length: 2,
width: 2,
height: 6,
},
healthPoints: 25,
name: 'Yasuo',
team: 'Runeterra',
weapons: [
'katana'
],
language: 'Samurai',
});

const katarina = new Villain({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 3,
},
healthPoints: 20,
name: 'Katarina',
team: 'Imperial',
weapons: [
'daggers'
],
language: 'French',
})


console.log(yasuo.attack(katarina)); // Hero attacks
console.log(katarina.stab(yasuo)); // Villian attacks
console.log(yasuo.attack(katarina)); // Hero attacks
console.log(yasuo.attack(katarina)); // Hero attacks
console.log(yasuo.attack(katarina)); // Hero attacks
76 changes: 70 additions & 6 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* The for principles of "this";
/* The four principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. If a function is in the global scope, the value of this will be the window
* 2. if you using an object .function, whatever this refers to in the function comes from that object
* 3. are you defining objects by a constructor, or with new syntax?
* 4. when call or apply are used, this is defined by that input
*
* write out a code example of each explanation above
*/
Expand All @@ -13,14 +13,78 @@

// code example for Window Binding

console.log(this);
function characterSpell1(){
console.log(this.spell);

}
//'use strict';
//characterSpell1();


// Principle 2

// code example for Implicit Binding
function characterSpell2(){
console.log(`This spell is ${this.spell}`);
}
const zed = {
name: 'Zed',
spell: 'Shuriken',
characterSpell3: function(){
console.log(`This spell 2nd example is ${this.spell}`);
}
}
zed.characterSpell3();

// Principle 3

// code example for New Binding

function LoLChar(name, role) {
this.name = name;
this.role = role;
this.declare = function () {
console.log(`Champion name: ${this.name} Champion role: ${this.role}`);
};
}

const ahri = new LoLChar('Ahri', 'Middle');
const qiyana = new LoLChar('Qiyana', 'Middle');

ahri.declare();
qiyana.declare();
// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
function talk () {
console.log(`My champion is ${this.name}`)
}

const champ = {
name: 'Zed',
spell: 'W',
}

talk.call(champ);


















let LoLChampArray = ["Ahri", "Akali", "Alistar", "Amumu", "Anivia", "Annie", "Ashe", "Blitzcrank", "Brand", "Caitlyn", "Cassiopeia", "Cho'gath", "Corki", "Dr. Mundo", "Evelynn", "Ezreal", "Fiddlesticks", "Fiora", "Fizz", "Galio", "Gangplank", "Garen", "Gragas", "Graves", "Hecarim", "Heimerdinger", "Irelia", "Janna", "Jarvan IV", "Jax", "Karma", "Karthus", "Kassadin", "Katarina", "Kayle", "Kennen", "Kog'Maw", "LeBlanc", "Lee Sin", "Leona", "Lulu", "Lux", "Malphite", "Malzahar", "Maokai", "Master Yi", "Miss Fortune", "Mordekaiser", "Morgana", "Nasus", "Nautilus", "Nidalee", "Nocturne", "Nunu", "Olaf", "Orianna", "Pantheon", "Poppy", "Rammus", "Renekton", "Riven", "Rumble", "Ryze", "Sejuani", "Shaco", "Shen", "Shyvana", "Singed", "Sion", "Sivir", "Skarner", "Sona", "Soraka", "Swain", "Talon", "Taric", "Teemo", "Tristana", "Trundle", "Trydamere", "Twisted Fate", "Twitch", "Udyr", "Urgot", "Varus", "Vayne", "Veigar", "Viktor", "Vladimir", "Volibear", "Warwick", "Wukong", "Xerath", "Xin Zhao", "Yorick", "Ziggs", "Zilean"];
console.log(LoLChampArray);
const newArray = [];