From b0f7c417d21f30eab83a1e5a7ae19fffbcbbd010 Mon Sep 17 00:00:00 2001 From: Steve Renner Date: Thu, 22 Aug 2019 13:41:49 -0700 Subject: [PATCH 1/3] 1st Push --- assignments/lambda-classes.js | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..a1c7c1441 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,59 @@ // CODE here for your Lambda Classes + +class Person{ + constructor(attributes){ + this.newName = attributes.newName + this.newAge = attributes.newAge + this.newLocation = attributes.newLocation + } + speak(){ + return `Hello my name is ${this.newName}, I am from ${this.newLocation}` + } +} + +class Instructor extends Person{ + constructor(instructorAttributes){ + super(instructorAttributes); + this.newSpecialty = redux + this.newFavLanguage = Javascript + this.newCatchPhrase = Ehhhh + } + demo(){ + return `Today we are learning about ${subject}` //Need to add a subject string as an argument + } + grade(){ + return `${student.name} receives a perfect score on {subject}` //Need to add student as an object and a subject string as arguments + } +} + +class Student extends Person{ + constructor(studentAttributes){ + super(studentAttributes); + this.previousBackground = McDonalds + this.className = Web23 + this.favSubjects = HTML + } + listsSubjects(){ //need a method that logs out all of the student's favoriteSubjects one by one + + } + PRAssignment(){ //need a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject} + + } + sprintChallenge(){ + return `${student.name} has begun sprint challenge on ${subject}` + } +} + +class ProjectManagers extends Instructor{ + constructor(ProjectManagersAttritubes){ + super(ProjectManagersAttritubes); + this.gradClassName = Web20 + this.favInstructor = Steven + } + standUp(){ + return `${name} announces to ${channel}, @channel standy times!` + } + debugsCode(){ + return `${name} debugs ${student.name}'s code on ${subject}` + } +} \ No newline at end of file From 1e144c3b13f49e028f720f7e49c2a3635160fa12 Mon Sep 17 00:00:00 2001 From: Steve Renner Date: Thu, 22 Aug 2019 14:31:07 -0700 Subject: [PATCH 2/3] Classes Draft --- assignments/lambda-classes.js | 49 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index a1c7c1441..e6b0fcf9e 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -14,14 +14,14 @@ class Person{ class Instructor extends Person{ constructor(instructorAttributes){ super(instructorAttributes); - this.newSpecialty = redux - this.newFavLanguage = Javascript - this.newCatchPhrase = Ehhhh + this.newSpecialty = instructorAttributes.specialty + this.newFavLanguage = instructorAttributes.favLanguage + this.newCatchPhrase = instructorAttributes.catchPhrase } - demo(){ + demo(subject){ return `Today we are learning about ${subject}` //Need to add a subject string as an argument } - grade(){ + grade(student, subject){ return `${student.name} receives a perfect score on {subject}` //Need to add student as an object and a subject string as arguments } } @@ -29,15 +29,15 @@ class Instructor extends Person{ class Student extends Person{ constructor(studentAttributes){ super(studentAttributes); - this.previousBackground = McDonalds - this.className = Web23 - this.favSubjects = HTML + this.previousBackground = studentAttributes.previousBackground + this.className = studentAttributes.className + this.favSubjects = studentAttributes.favSubjects } listsSubjects(){ //need a method that logs out all of the student's favoriteSubjects one by one } PRAssignment(){ //need a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject} - + return `${student.name} has submitted a PR for ${subject}` } sprintChallenge(){ return `${student.name} has begun sprint challenge on ${subject}` @@ -47,13 +47,36 @@ class Student extends Person{ class ProjectManagers extends Instructor{ constructor(ProjectManagersAttritubes){ super(ProjectManagersAttritubes); - this.gradClassName = Web20 - this.favInstructor = Steven + this.gradClassName = ProjectManagersAttritubes.gradClassName + this.favInstructor = ProjectManagersAttritubes.favInstructor } standUp(){ return `${name} announces to ${channel}, @channel standy times!` } - debugsCode(){ + debugsCode(student){ return `${name} debugs ${student.name}'s code on ${subject}` } -} \ No newline at end of file +} + +const Steve = new Person({ + name: 'Steve', + age: 41, + location: 'Seattle', +}) + +const Brit = new Instructor({ + specialty: 'teaching', + favLanguage: 'JavaScript', + catchPhrase: 'Ehhhh', +}) + +const Skippy = new Student({ + previousBackground: 'McDonalds', + className: 'Web23', + favSubjects: 'HTML', +}) + +const Tyler = new ProjectManagers({ + gradClassName: 'Web1', + favInstructor: 'Shanaynay', +}) From 3b4f5be29b602438e3cf1467f24511051df09dd3 Mon Sep 17 00:00:00 2001 From: Steve Renner Date: Thu, 22 Aug 2019 16:02:10 -0700 Subject: [PATCH 3/3] 4pm Turn In --- assignments/prototype-refactor.js | 152 ++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..4e6147657 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,155 @@ 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. */ +// 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 + * takeDamage() // prototype method -> returns the string ' took damage.' + * should inherit destroy() from GameObject's prototype + */ + +// function CharacterStats(attributes2) { +// GameObject.call(this, attributes2); +// this.healthPoints = attributes2.healthPoints; +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); +class CharacterStats{ + constructor(attributes2) { + GameObject.call(this, attributes2); + this.healthPoints = attributes2.healthPoints; + } + // CharacterStats.prototype = Object.create(GameObject.prototype); + takeDamage() { + return `${this.name} took damage`; + } +} + +// 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(attributes3) { +// CharacterStats.call(this, attributes3); +// this.team = attributes3.team; +// this.weapons = attributes3.weapons; +// this.language = attributes3.language; +// } + +class Humanoid{ + constructor(attributes3) { + this.team = attributes3.team; + this.weapons = attributes3.weapons; + this.language = attributes3.language; + } + greet() { + return `${this.name} offers a greeting in ${this.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. + \ No newline at end of file