From 9ec094580047f70541eae7796734baca4f18929c Mon Sep 17 00:00:00 2001 From: Lisa Campbell Date: Wed, 29 May 2019 18:15:37 -0700 Subject: [PATCH 1/5] Initial commit. Updated README and pasted code from JS3 prototype. --- README.md | 16 ++-- assignments/prototype-refactor.js | 141 ++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2c59e6c4f..044545723 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,17 @@ This challenge focuses on classes in JavaScript using the new `class` keyword. **Follow these steps to set up and work on your project:** -* [ ] Create a forked copy of this project. -* [ ] Add your project manager as collaborator on Github. -* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). -* [ ] Create a new branch: git checkout -b ``. -* [ ] Implement the project on your newly created `` branch, committing changes regularly. -* [ ] Push commits: git push origin ``. +* [X] Create a forked copy of this project. +* [X] Add your project manager as collaborator on Github. +* [X] Clone your OWN version of the repository (Not Lambda's by mistake!). +* [X] Create a new branch: git checkout -b ``. +* [X] Implement the project on your newly created `` branch, committing changes regularly. +* [X] Push commits: git push origin ``. **Follow these steps for completing your project.** -* [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** -* [ ] Add your project manager as a reviewer on the pull-request +* [X] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** +* [X] Add your project manager as a reviewer on the pull-request * [ ] Your project manager will count the project as complete by merging the branch back into master. ## Assignment Description diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..4f14fce4e 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,144 @@ 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. */ + +/* + Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy. + + In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. + + At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions. + + 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(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 ' took damage.' + * should inherit destroy() from GameObject's prototype + */ + + function CharacterStats(attributes) { + GameObject.call(this, attributes); + this.healthPoints = attributes.healthPoints; + } + + CharacterStats.prototype.takeDamage = function() { + return `${this.name} took damage.` + } + + /* + === Humanoid (Having an appearance or character resembling that of a human.) === + * team + * weapons + * language + * greet() // prototype method -> returns the string ' offers a greeting in .' + * 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 = 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. + * 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, + 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. + + + // 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! From 042b8e4c0a733f4be694fc3bf0e563247cda27d8 Mon Sep 17 00:00:00 2001 From: Lisa Campbell Date: Wed, 29 May 2019 18:18:36 -0700 Subject: [PATCH 2/5] Branched incorrectly. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 044545723..7f9470259 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This challenge focuses on classes in JavaScript using the new `class` keyword. * [X] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** * [X] Add your project manager as a reviewer on the pull-request -* [ ] Your project manager will count the project as complete by merging the branch back into master. +* [X] Your project manager will count the project as complete by merging the branch back into master. ## Assignment Description From d4aa50e70cf4589709128d63fb9629740186f89e Mon Sep 17 00:00:00 2001 From: Lisa Campbell Date: Wed, 29 May 2019 21:17:06 -0700 Subject: [PATCH 3/5] Finished prototype-refactor.js. --- assignments/prototype-refactor.js | 69 +++++++++++++++++-------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 4f14fce4e..67b266766 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -25,16 +25,17 @@ Prototype Refactor * 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.` - } - +/ + 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.` + } + } /* === CharacterStats === * healthPoints @@ -42,15 +43,17 @@ function GameObject(attributes) { * should inherit destroy() from GameObject's prototype */ - function CharacterStats(attributes) { - GameObject.call(this, attributes); - this.healthPoints = attributes.healthPoints; - } - - CharacterStats.prototype.takeDamage = function() { - return `${this.name} took damage.` - } - + + class CharacterStats extends GameObject { + constructor(attributes) { + super(attributes); + this.healthPoints = attributes.healthPoints; + } + + takeDamage() { + return `${this.name} took damage.` + } + } /* === Humanoid (Having an appearance or character resembling that of a human.) === * team @@ -61,18 +64,22 @@ function GameObject(attributes) { * 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 = Object.create(CharacterStats.prototype); - - Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; - } + class Humanoid extends CharacterStats { + constructor(attributes) { + super(attributes); + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + + destroy() { + return `${this.name} was removed from the game.` + } + + greet() { + 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. From 011a7e70c3ddb872cbce02f3ac94dfb596ed1500 Mon Sep 17 00:00:00 2001 From: Lisa Campbell Date: Thu, 30 May 2019 20:49:22 -0700 Subject: [PATCH 4/5] Created classes for Person, Instructor, Student and Project Manager. --- assignments/lambda-classes.js | 117 ++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..4145d00d8 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,118 @@ // CODE here for your Lambda Classes + +//Person-Base Class +class Person { + 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}.`; + } +} + +//Instructor +class Instructor extends Person { + constructor(attributes) { + super(attributes); + this.specialty = attributes.specialty; + this.favLanguage = attributes.favLanguage; + this.catchPhrase = attributes.catchPhrase; + } + + demo(subject) { + return`Today we are learning about ${subject}`; + } + + grade(student) { + return`${this.name} receives a perfect score on ${subject}`; + } +} + +//Student +class Student extends Person { + constructor(attributes) { + super(attributes); + this.previousBackground = attributes.previousBackground; + this.className = attributes.className; + this.favSubjects = attributes.favSubjects; + } + + listSubjects() { + favSubjects.forEach(function(subject) { + return subject; + } + )} + + PRAssignment(subject) { + return`${this.name} has submitted a PR for ${subject}`; + } + + sprintChallenge(subject) { + return`${this.name} has begun sprint challenge on ${subject}`; + } +} + +//Project Manager +class ProjectManager extends Instructor { + constructor(attributes) { + super(attributes); + this.gradClassName = attributes.gradClassName; + this.favInstructor = attributes.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}`; + } +} + + +//New Instructor +const fred = new Instructor ({ + name: 'Fred', + location: 'Bedrock', + age: 37, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies` +}) + +//New Student +const lisa = new Student ({ + name: 'Lisa', + location: 'Los Angeles', + age: 40, + favLanguage: 'Still deciding', + specialty: 'Front-end eventually', + catchPhrase: `Don't have one`, + previousBackground: 'Stay at home mom', + className: 'WebPT7', + favSubjects: ['CSS', 'HTML', 'JS'] + }) + +//New PM +const jasmine = new ProjectManager ({ + name: 'Jasmine', + location: 'Texas', + age: 23, + favLanguage: 'Javascript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies`, + gradClassName: 'Web5', + favInstructor: 'Dan Frehner' +}) + +// console.log(fred.speak()); +// console.log(fred.demo('HTML')); + +// console.log(lisa.PRAssignment('JS')); +console.log(lisa.listSubjects()); +// console.log(lisa.sprintChallenge('JS')); + +// console.log(jasmine.debugsCode('Student.lisa', 'JS')); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 67b266766..f65fd4451 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -25,7 +25,7 @@ Prototype Refactor * dimensions (These represent the character's size in the video game) * destroy() // prototype method that returns: `${this.name} was removed from the game.` */ -/ + class GameObject { constructor(attributes) { this.createdAt = attributes.createdAt; From d1bb27428c3e8583dccd67ddad146c9b50672b84 Mon Sep 17 00:00:00 2001 From: Lisa Campbell Date: Fri, 31 May 2019 09:54:05 -0700 Subject: [PATCH 5/5] Completed lambda-classes.js. --- assignments/lambda-classes.js | 174 +++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 79 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 4145d00d8..978f49271 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -2,117 +2,133 @@ //Person-Base Class class Person { - constructor(attributes) { - this.name = attributes.name; - this.age = attributes.age; - this.location = attributes.location; - } + 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}.`; - } + speak() { + return`Hello my name is ${this.name}, I am from ${this.location}.`; + } } //Instructor class Instructor extends Person { - constructor(attributes) { - super(attributes); - this.specialty = attributes.specialty; - this.favLanguage = attributes.favLanguage; - this.catchPhrase = attributes.catchPhrase; - } + constructor(attributes) { + super(attributes); + this.specialty = attributes.specialty; + this.favLanguage = attributes.favLanguage; + this.catchPhrase = attributes.catchPhrase; + } - demo(subject) { - return`Today we are learning about ${subject}`; - } - - grade(student) { - return`${this.name} receives a perfect score on ${subject}`; - } + demo(subject) { + return`Today we are learning about ${subject}`; + } + + grade(student) { + return`${this.name} receives a perfect score on ${subject}`; + } } //Student class Student extends Person { - constructor(attributes) { - super(attributes); - this.previousBackground = attributes.previousBackground; - this.className = attributes.className; - this.favSubjects = attributes.favSubjects; - } - - listSubjects() { - favSubjects.forEach(function(subject) { - return subject; - } - )} - - PRAssignment(subject) { - return`${this.name} has submitted a PR for ${subject}`; - } + constructor(attributes) { + super(attributes); + this.previousBackground = attributes.previousBackground; + this.className = attributes.className; + this.favSubjects = attributes.favSubjects; + } + + listSubjects() { + let result = ""; + this.favSubjects.forEach(function(subject) { + result = `${result}${subject}\n`; + }); + + return result; + } - sprintChallenge(subject) { - return`${this.name} has begun sprint challenge on ${subject}`; - } + PRAssignment(subject) { + return`${this.name} has submitted a PR for ${subject}`; + } + + sprintChallenge(subject) { + return`${this.name} has begun sprint challenge on ${subject}`; + } } //Project Manager class ProjectManager extends Instructor { - constructor(attributes) { - super(attributes); - this.gradClassName = attributes.gradClassName; - this.favInstructor = attributes.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}`; - } + constructor(attributes) { + super(attributes); + this.gradClassName = attributes.gradClassName; + this.favInstructor = attributes.favInstructor; + } + + standUp(slackChannel) { + return `${this.name} announces to ${slackChannel}, @channel standy times!`; + } + + debugsCode(student, subject) { + return`${this.name} debugs ${student}'s code on ${subject}`; + } } //New Instructor const fred = new Instructor ({ - name: 'Fred', - location: 'Bedrock', - age: 37, - favLanguage: 'JavaScript', - specialty: 'Front-end', - catchPhrase: `Don't forget the homies` + name: 'Fred', + location: 'Bedrock', + age: 37, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies` +}) + +const marc = new Instructor ({ + name: 'Marc', + location: 'Los Angeles', + age: 44, + favLanguage: 'Erlang', + specialty: 'SaaS', + catchPhrase: 'Deploy often' }) //New Student const lisa = new Student ({ - name: 'Lisa', - location: 'Los Angeles', - age: 40, - favLanguage: 'Still deciding', - specialty: 'Front-end eventually', - catchPhrase: `Don't have one`, - previousBackground: 'Stay at home mom', - className: 'WebPT7', - favSubjects: ['CSS', 'HTML', 'JS'] + name: 'Lisa', + location: 'Los Angeles', + age: 40, + favLanguage: 'Still deciding', + specialty: 'Front-end eventually', + catchPhrase: `Don't have one`, + previousBackground: 'Stay at home mom', + className: 'WebPT7', + favSubjects: ['CSS', 'HTML', 'JS'] }) //New PM const jasmine = new ProjectManager ({ - name: 'Jasmine', - location: 'Texas', - age: 23, - favLanguage: 'Javascript', - specialty: 'Front-end', - catchPhrase: `Don't forget the homies`, - gradClassName: 'Web5', - favInstructor: 'Dan Frehner' + name: 'Jasmine', + location: 'Texas', + age: 23, + favLanguage: 'Javascript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies`, + gradClassName: 'Web5', + favInstructor: 'Dan Frehner' }) // console.log(fred.speak()); // console.log(fred.demo('HTML')); +//console.log(marc.speak()); +//console.log(marc.demo('HTML')); + // console.log(lisa.PRAssignment('JS')); -console.log(lisa.listSubjects()); -// console.log(lisa.sprintChallenge('JS')); +//console.log(lisa.listSubjects()); +//console.log(lisa.sprintChallenge('JS')); -// console.log(jasmine.debugsCode('Student.lisa', 'JS')); \ No newline at end of file +//console.log(jasmine.standUp('web help')); +console.log(jasmine.debugsCode('Lisa', 'JS')); \ No newline at end of file