From b86c97ceddb49e165aa4ebc7956168da1545327a Mon Sep 17 00:00:00 2001 From: ItelSunday Date: Thu, 24 Jan 2019 10:35:14 -0800 Subject: [PATCH 1/5] initial commit --- assignments/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/index.html b/assignments/index.html index 2fc751cde..314f91199 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -7,8 +7,8 @@ JS IV - - + + From 1787118c5f0812e65e3d2adccea9922e727a70b7 Mon Sep 17 00:00:00 2001 From: ItelSunday Date: Thu, 24 Jan 2019 16:35:37 -0800 Subject: [PATCH 2/5] added prototypes --- assignments/prototype-refactor.js | 120 +++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..aac715c0d 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,9 +1,123 @@ /* - Prototype Refactor 1. Copy and paste your code or the solution from yesterday - 2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them. - */ + + +/*=== GameObject ===*/ +// function GameObject(game){ +// this.createdAt = game.createdAt; +// this.dimensions = game.dimensions; +// } +// GameObject.prototype.destroy = function() { +// return `${this.name} removed from the game`; +// }; + + /* REFACTOR: GameObject */ +class GameObject{ + constructor(game){ + this.createdAt = game.createdAt; + this.dimensions = game.dimensions; + } + destroy(){ + return `${this.name} removed from the game`; + } +} + + + /*=== CharacterStats ===*/ + + function CharacterStats(character){ + GameObject.call(this,character); + this.healthPoints = character.healthPoints; + this.name = character.name; + } + CharacterStats.prototype = Object.create(GameObject.prototype); + + CharacterStats.prototype.takeDamage = function(){ + return `${this.name} took damage`; + }; + + /* REFACTOR: CharacterStats */ + + /* === Humanoid ===*/ + function Humanoid(human){ + CharacterStats.call(this, human); //.apply(this, [human]); refers to arrays + this.team = human.team; + this.weapons = human.weapons; + this.language = human.language; + } + Humanoid.prototype = Object.create(CharacterStats.prototype); + + Humanoid.prototype.greet = function() { + return `${this.name} offers a greeting in ${this.language}`; + }; + + /* REFACTOR: Humanoid */ + + /* Onjects */ + + const mage = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 1, + height: 1, + }, + healthPoints: 5, + name: 'Bruce', + team: 'Mage Guild', + weapons: [ + 'Staff of Shamalama', + ], + language: 'Common Tongue', + }); + + const swordsman = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 2, + height: 2, + }, + healthPoints: 15, + name: 'Sir Mustachio', + team: 'The Round Table', + weapons: [ + 'Giant Sword', + 'Shield', + ], + language: 'Common Tongue', + }); + + const archer = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + healthPoints: 10, + name: 'Lilith', + team: 'Forest Kingdom', + weapons: [ + 'Bow', + 'Dagger', + ], + language: 'Elvish', + }); + + console.log(mage.createdAt); // Today's date + console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } + console.log(swordsman.healthPoints); // 15 + console.log(mage.name); // Bruce + console.log(swordsman.team); // The Round Table + console.log(mage.weapons); // Staff of Shamalama + console.log(archer.language); // Elvish + 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. + + From 4c068e0b97fde5c5d1f29713b2242733f53ed7bb Mon Sep 17 00:00:00 2001 From: ItelSunday Date: Fri, 25 Jan 2019 01:28:37 -0800 Subject: [PATCH 3/5] added sub-classes --- assignments/prototype-refactor.js | 68 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index aac715c0d..b7c49c320 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -25,39 +25,61 @@ class GameObject{ return `${this.name} removed from the game`; } } - /*=== CharacterStats ===*/ +// function CharacterStats(character){ +// GameObject.call(this,character); +// this.healthPoints = character.healthPoints; +// this.name = character.name; +// } +// CharacterStats.prototype = Object.create(GameObject.prototype); - function CharacterStats(character){ - GameObject.call(this,character); - this.healthPoints = character.healthPoints; - this.name = character.name; - } - CharacterStats.prototype = Object.create(GameObject.prototype); - - CharacterStats.prototype.takeDamage = function(){ - return `${this.name} took damage`; - }; +// CharacterStats.prototype.takeDamage = function(){ +// return `${this.name} took damage`; +// }; /* REFACTOR: CharacterStats */ + class CharacterStats extends GameObject { + constructor(character) { + super (character); + this.healthPoints = character.healthPoints; + this.name = character.name; + } + takeDamage(){ + return `${this.name} took damage`; + } + } + /* === Humanoid ===*/ - function Humanoid(human){ - CharacterStats.call(this, human); //.apply(this, [human]); refers to arrays - this.team = human.team; - this.weapons = human.weapons; - this.language = human.language; - } - Humanoid.prototype = Object.create(CharacterStats.prototype); +// function Humanoid(human){ +// CharacterStats.call(this, human); //.apply(this, [human]); refers to arrays +// this.team = human.team; +// this.weapons = human.weapons; +// this.language = human.language; +// } +// Humanoid.prototype = Object.create(CharacterStats.prototype); - Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}`; - }; +// Humanoid.prototype.greet = function() { +// return `${this.name} offers a greeting in ${this.language}`; +// }; /* REFACTOR: Humanoid */ - - /* Onjects */ + class humanoid extends CharacterStats { + constructor(human) { + super (human); + this.team = human.team; + this.weapons = human.weapons; + this.language = human.language; + } + greet() { + return `${this.name} offers a greeting in ${this.language}`; + } + } + + + + /* Objects */ const mage = new Humanoid({ createdAt: new Date(), From 4aecf73664edb2d082d2f357764e26c4eeafca54 Mon Sep 17 00:00:00 2001 From: ItelSunday Date: Fri, 25 Jan 2019 01:42:29 -0800 Subject: [PATCH 4/5] fixed function class --- assignments/prototype-refactor.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index b7c49c320..5afc55e31 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -65,7 +65,7 @@ class GameObject{ // }; /* REFACTOR: Humanoid */ - class humanoid extends CharacterStats { + class Humanoid extends CharacterStats { constructor(human) { super (human); this.team = human.team; @@ -77,8 +77,6 @@ class GameObject{ } } - - /* Objects */ const mage = new Humanoid({ From f2e2dbba9733cc776e7996bbc1c9d3fe28235af1 Mon Sep 17 00:00:00 2001 From: ItelSunday Date: Fri, 25 Jan 2019 02:26:38 -0800 Subject: [PATCH 5/5] listed requirements --- assignments/lambda-classes.js | 67 ++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..7105ada5b 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,66 @@ -// CODE here for your Lambda Classes +//Lambda Classes + +/*Lambda Personnel */ + +/* Students - ext of Person */ +/* Instructors - ext of Person */ +/* Project Managers - ext of Instructors */ + + +/* Objects */ +/* Person */ +/* +Requirements: + 1. base-class + 2. Attr: name, age, location, gender + 3. Phrase/logs out: "Hello my name is Fred, I am from Bedrock` where `name` and `location`" + 4. Method: name.speak() +*/ +const fred = new Instructor({ + name: 'Fred', + location: 'Bedrock', + age: 37, + gender: 'male', + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies` + }); + + + + +/* Students */ +/* +Requirements: + 1. Attr: name, age, location, gender + 2. Props: previousBackground, className, favSubjects, + listsSubjects - logs out all of the student's favoriteSubjects one by one., + PRAssignment - logs out `student.name has submitted a PR for {subject}` + sprintChallenge - logs out `student.name has begun sprint challenge on {subject}` + +*/ +const jade = new Student({ + name: "Jade", + +}); + +/* Instructors */ +/* +Requirements: + 1. Attr: name, age, location, gender + 2. Props: specialty, favLanguage, catchPhrase + 3. Method: name.demo() + logs out: "Today we are learning about {subject}' where subject is the param passed in." + 4. Method: name.grade() + logs out: {student.name} receives a perfect score on {subject} +*/ + +/* Project Managers */ +/* +Requirements: + 1. Props: gradClassName, favInstructor, + standUp - takes in a slack channel + logs out: `{name} announces to {channel}, @channel standy times!​​​​​ + debugsCode - takes in a student object and a subject + logs out: `{name} debugs {student.name}'s code on {subject}` +*/ \ No newline at end of file