From 6dcec4caa5bd14b950806bc5e109989bbef99e40 Mon Sep 17 00:00:00 2001 From: Brendan Schatz Date: Thu, 19 Sep 2019 15:54:52 -0400 Subject: [PATCH 1/3] refactor MVP --- assignments/prototype-refactor.js | 170 ++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..85c1c815c 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,3 +1,4 @@ +"use strict" /* Prototype Refactor @@ -7,3 +8,172 @@ Prototype Refactor 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. */ + +class GameObject{ + constructor(attributes) { + this.createdAt = attributes.createdAt, + this.name = attributes.name, + this.dimensions = attributes.dimensions + }; + destroy() { + return `${this.Name} was removed from the game`; + } +} + + +class CharacterStats extends GameObject { + constructor(stats) { + super(stats); + this.healthPoints = stats.healthPoints; + this.attackPoints = stats.attackPoints; + } + takeDamage() { + return `${this.name} took ${this.attackPoints} damage`; + } +} + + +class Humanoid extends CharacterStats { + constructor(args) { + super(args); + this.team = args.team; + this.weapons = args.weapons; + this.language = args.language; + }; + + greet() { + return `${this.name} offers a greeting in ${this.language}`; + } + + getHit(attacker) { + this.healthPoints = this.healthPoints - attacker.attackPoints; + if (this.healthPoints > 0) { + return `${this.name} took ${attacker.attackPoints} points of damage he now has ${this.healthPoints} health left` + } + else { + return `${this.name} took ${attacker.attackPoints} points of damage he now has ${this.healthPoints} and is dead` + } + } + + attack(opponent) { + return `${this.name} uses his ${this.weapons} to attack ${opponent.name} for ${this.attackPoints}` + } +} + + +class EvilCharacter extends Humanoid { + constructor(args) { + super(args); + } + attack() { + return `${this.name} uses his ${this.weapons[0]} to attack ${mage.name} for ${this.attackPoints}` + } + + threaten() { + return `I ${this.name} will destroy you!!!` + } +} + + +/* + * Inheritance chain: GameObject -> CharacterStats -> Humanoid + * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. + * Instances of CharacterStats should have all of the same properties as GameObject. +*/ + +// Test you work by un-commenting these 3 objects and the list of console logs below: + + +const mage = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 1, + height: 1, + }, + healthPoints: 5, + attackPoints: 7, + 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', +}); + + +const badGuy = new EvilCharacter({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 2, + height: 3 + }, + healthPoints: 15, + attackPoints: 3, + name: "Sir EVILTON", + team: "THE GROUP OF EV1L", + weapons: [ + "Fists", + "Feet", + ], + language: "Common Tongue", +}) + + + + +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. + + +console.log(badGuy.greet()); +console.log(badGuy.threaten()); +console.log(badGuy.attack()); +console.log(mage.getHit(badGuy)); +console.log(mage.attack(badGuy)); +console.log(badGuy.getHit(mage)); +console.log(mage.getHit(badGuy)); +console.log(mage.destroy()); From f27f60d2530bfa35f0f8791ebceda2494f7f7da9 Mon Sep 17 00:00:00 2001 From: Brendan Schatz Date: Thu, 19 Sep 2019 16:49:11 -0400 Subject: [PATCH 2/3] COMPLETED MVP for the Project. --- assignments/lambda-classes.js | 113 ++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 2 +- 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..edbf2cb69 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,114 @@ // CODE here for your Lambda Classes + + +class PersonClass { + constructor(attributes){ + this.name = attributes.name, + this.age = attributes.age, + this.location = attributes.location + }; + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}` + }; +}; + +class Instructor extends PersonClass { + constructor(prefs) { + super(prefs), + this.specialty = prefs.specialty, + this.favLanguage = prefs.favLanguage, + this.catchPhrase = prefs.catchPhrase + }; + demo(subject) { + return `Today we are learning about ${subject} where subject is the param passed in` + }; + grade(student, subject) { + return `${student.name} receives a perfect score on ${subject}` + }; +} + + +class Student extends PersonClass { + constructor(knowledge) { + super(knowledge), + this.previousBackground = knowledge.previousBackground, + this.className = knowledge.className, + this.favSubjects = knowledge.favSubjects + }; + listsSubjects() { + return `${this.name}'s favorite subjects are ${this.favSubjects}` + } + PRAssignment (subject) { + return `${this.name} has submitted a PR for ${subject}` + } + sprintChallenge (subject) { + return `${this.name} has begun sprint challenge on ${subject}` + } +} + +class ProjectManager extends Instructor { + constructor(specialty) { + super(specialty), + this.gradClassName = specialty.gradClassName, + this.favInstructor = specialty.favInstructor + } + standUp (slackChannel) { + return `${this.name} announces to ${slackChannel} @channel standy times!` + } + debugsCode(student, subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}` + } +} + +const fred = new Instructor({ + name: 'Fred', + location: 'Bedrock', + age: 37, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies` + }); + + const ObiWan = new Instructor({ + name: 'Obi Wan', + location: 'Tatooin', + age: 84, + favLanguage: 'Condecending', + specialty: 'Training Sith Lords', + catchPhrase: `I have the high ground` + }); + + const Yoda = new ProjectManager({ + name: 'Yoda', + location: 'Afterlife', + age: 637, + favLanguage: 'Metaphors', + specialty: 'The force', + catchPhrase: `Do or do not. There is no try.`, + gradClassName: 'Too long ago to remember', + favInstructor: 'Mace Windu was my BOI' + }); + + const Emporer = new ProjectManager({ + name: 'Palpaltine', + location: 'The Heart of a volcano', + age: 137, + favLanguage: 'Cackling', + specialty: 'The Dark Side', + catchPhrase: `Do It!!!!`, + gradClassName: 'Darth Plagus', + favInstructor: 'Myself HAHAHAHA' + }); + + const Luke = new Student({ + name: 'Luke', + location: 'Who Cares?', + age: 70, + previousBackground: "Building sand castles", + className: 'Yodas school for the gifted', + favSubjects: ['Running through trees', 'Flipping over rocks', 'Carrying Yoda like a baby'] + }); + + console.log(Luke); + console.log(Emporer.standUp("SithLords")) + console.log(ObiWan.speak()) \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 85c1c815c..66ca0a7f9 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -16,7 +16,7 @@ class GameObject{ this.dimensions = attributes.dimensions }; destroy() { - return `${this.Name} was removed from the game`; + return `${this.name} was removed from the game`; } } From 6d4f429ea6250ba1912086d216bd2187b0a4c85d Mon Sep 17 00:00:00 2001 From: Brendan Schatz Date: Thu, 19 Sep 2019 18:26:17 -0400 Subject: [PATCH 3/3] MVP + STRETCH --- assignments/lambda-classes.js | 85 +++++++++++++++++++------------ assignments/prototype-refactor.js | 24 ++++----- 2 files changed, 64 insertions(+), 45 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index edbf2cb69..9a4bfd3de 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1,58 +1,72 @@ // CODE here for your Lambda Classes - class PersonClass { - constructor(attributes){ + constructor(attributes) { this.name = attributes.name, - this.age = attributes.age, - this.location = attributes.location + this.age = attributes.age, + this.location = attributes.location }; speak() { - return `Hello my name is ${this.name}, I am from ${this.location}` + return `Hello my name is ${this.name}, I am from ${this.location}` }; }; class Instructor extends PersonClass { constructor(prefs) { super(prefs), - this.specialty = prefs.specialty, - this.favLanguage = prefs.favLanguage, - this.catchPhrase = prefs.catchPhrase + this.specialty = prefs.specialty, + this.favLanguage = prefs.favLanguage, + this.catchPhrase = prefs.catchPhrase }; demo(subject) { - return `Today we are learning about ${subject} where subject is the param passed in` + return `Today we are learning about ${subject} where subject is the param passed in` }; grade(student, subject) { - return `${student.name} receives a perfect score on ${subject}` + return `${student.name} receives a perfect score on ${subject}` }; + assignScore() { + return Math.floor(Math.random() * Math.floor(100)); + } } class Student extends PersonClass { constructor(knowledge) { super(knowledge), - this.previousBackground = knowledge.previousBackground, - this.className = knowledge.className, - this.favSubjects = knowledge.favSubjects + this.previousBackground = knowledge.previousBackground, + this.className = knowledge.className, + this.favSubjects = knowledge.favSubjects, + this.grade = knowledge.grade }; listsSubjects() { return `${this.name}'s favorite subjects are ${this.favSubjects}` } - PRAssignment (subject) { - return `${this.name} has submitted a PR for ${subject}` + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}` + } + sprintChallenge(subject) { + return `${this.name} has begun sprint challenge on ${subject}` } - sprintChallenge (subject) { - return `${this.name} has begun sprint challenge on ${subject}` + graduate() { + this.grade = Math.floor(Math.random() * Math.floor(100)); + + if (this.grade > 70) { + return `Congratulations you graduate Lambda with a ${this.grade}%` + } + else { + return `Sorry you failed to graduate because ${this.grade}% is not passing` + } } + } class ProjectManager extends Instructor { constructor(specialty) { super(specialty), - this.gradClassName = specialty.gradClassName, - this.favInstructor = specialty.favInstructor + this.gradClassName = specialty.gradClassName, + this.favInstructor = specialty.favInstructor } - standUp (slackChannel) { + standUp(slackChannel) { return `${this.name} announces to ${slackChannel} @channel standy times!` } debugsCode(student, subject) { @@ -67,18 +81,18 @@ const fred = new Instructor({ favLanguage: 'JavaScript', specialty: 'Front-end', catchPhrase: `Don't forget the homies` - }); +}); - const ObiWan = new Instructor({ +const ObiWan = new Instructor({ name: 'Obi Wan', location: 'Tatooin', age: 84, favLanguage: 'Condecending', specialty: 'Training Sith Lords', catchPhrase: `I have the high ground` - }); +}); - const Yoda = new ProjectManager({ +const Yoda = new ProjectManager({ name: 'Yoda', location: 'Afterlife', age: 637, @@ -87,9 +101,9 @@ const fred = new Instructor({ catchPhrase: `Do or do not. There is no try.`, gradClassName: 'Too long ago to remember', favInstructor: 'Mace Windu was my BOI' - }); +}); - const Emporer = new ProjectManager({ +const Emporer = new ProjectManager({ name: 'Palpaltine', location: 'The Heart of a volcano', age: 137, @@ -98,17 +112,22 @@ const fred = new Instructor({ catchPhrase: `Do It!!!!`, gradClassName: 'Darth Plagus', favInstructor: 'Myself HAHAHAHA' - }); +}); - const Luke = new Student({ +const Luke = new Student({ name: 'Luke', location: 'Who Cares?', age: 70, previousBackground: "Building sand castles", className: 'Yodas school for the gifted', - favSubjects: ['Running through trees', 'Flipping over rocks', 'Carrying Yoda like a baby'] - }); + favSubjects: ['Running through trees', 'Flipping over rocks', 'Carrying Yoda like a baby'], + grade: 80 +}); + +console.log(Luke); +console.log(Emporer.standUp("SithLords")) +console.log(ObiWan.speak()) + - console.log(Luke); - console.log(Emporer.standUp("SithLords")) - console.log(ObiWan.speak()) \ No newline at end of file +console.log(Yoda.assignScore()) +console.log(Luke.graduate()); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 66ca0a7f9..79d9c726d 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -144,11 +144,11 @@ const badGuy = new EvilCharacter({ height: 3 }, healthPoints: 15, - attackPoints: 3, + attackPoints: 4, name: "Sir EVILTON", team: "THE GROUP OF EV1L", weapons: [ - "Fists", + "Dagger", "Feet", ], language: "Common Tongue", @@ -157,16 +157,16 @@ const badGuy = new EvilCharacter({ -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. +// 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. console.log(badGuy.greet());