From 9a7e8620487aad6593eb97b707c9758dff818888 Mon Sep 17 00:00:00 2001 From: miriam-sullivan Date: Thu, 19 Sep 2019 14:03:54 -0500 Subject: [PATCH 1/4] copied code from yesterday --- assignments/prototype-refactor.js | 142 ++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..43136ed83 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,145 @@ 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 = GameObject.prototype; +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 = 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. + From 2187a23fb13ca658bfdf5213df7e7c20d6b4c481 Mon Sep 17 00:00:00 2001 From: miriam-sullivan Date: Thu, 19 Sep 2019 15:28:31 -0500 Subject: [PATCH 2/4] I finished prototype-refractor --- assignments/lambda-classes.js | 68 +++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 61 ++++++++++++--------------- 2 files changed, 94 insertions(+), 35 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..99d1d3b5d 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,69 @@ // CODE here for your Lambda Classes +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}`; + } +} + +class Instructor extends Person{ + constructor(InstructorAttributes){ + super(InstructorAttributes); + this.specialty = InstructorAttributes.specialty, + this.favLanguage = InstructorAttributes.favLanguage, + this.catchPhrase = InstructorAttributes.catchPhrase + } + demo(_subject){ + return `Today we are learning about ${this.subject}` + } + grade(_student, _object){ + return `${this.student.name} receives a perfect score on ${this.subject}`; + } + + + +} + +class Student extends Instructor{ + constructor(StudentAttributes){ + super(StudentAttributes); + this.previousBackground = StudentAttributes.previousBackground, + this.className = StudentAttributes.className, + this.favSubjects = StudentAttributes.favSubjects + } + listsSubjects(){ + return `${this.favSubjects}` + } + PRAssignment(_name, _subject){ + return `${this.student.name} has submitted a PR for ${this.subject}`; + } + + +} + + + + + + + +} + +class ProjectManager extends Student{ + constructor(ProjectManagerAttributes){ + super(ProjectManagerAttributes); + + + + } + + + + + +} + diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 43136ed83..cb9d12c56 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -6,16 +6,6 @@ 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 @@ -24,16 +14,17 @@ Each constructor function has unique properties and methods that are defined in * destroy() // prototype method that returns: `${this.name} was removed from the game.` */ -function GameObject(attributes) { +class GameObject{ + constructor(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` -}; + } + destroy() { + return `${this.name} was removed from the game` + } +} @@ -43,15 +34,15 @@ return `${this.name} was removed from the game` * 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 = GameObject.prototype; -CharacterStats.prototype.takeDamage = function () { -return `${this.name} took damage.` -}; - +class CharacterStats extends GameObject{ + constructor(childAttributes){ + super(childAttributes); + this.healthPoints = childAttributes.healthPoints + } + takeDamage(_destroy) { + return `${this.name} took damage.` + }; +} /* === Humanoid (Having an appearance or character resembling that of a human.) === @@ -63,17 +54,17 @@ return `${this.name} took damage.` * should inherit takeDamage() from CharacterStats */ -function Humanoid(attributes) { -CharacterStats.call(this, attributes), -this.team = attributes.team, -this.weapons = attributes.weapons, -this.language = attributes.language +class Humanoid extends CharacterStats { + constructor(grandChildAttributes) { + super(grandChildAttributes); + this.team = grandChildAttributes.team, + this.weapons = grandChildAttributes.weapons, + this.language = grandChildAttributes.language + } + greet(_destroy, _takeDamage) { + return `${this.name} offers a greeting in ${this.language}.` + }; } -Humanoid.prototype = CharacterStats.prototype; -Humanoid.prototype.greet = function () { -return `${this.name} offers a greeting in ${this.language}.` -}; - From 26ce06e6967da7ee0f9db4d37489aceb90b08fdd Mon Sep 17 00:00:00 2001 From: miriam-sullivan Date: Thu, 19 Sep 2019 16:07:22 -0500 Subject: [PATCH 3/4] almost done with everything --- assignments/lambda-classes.js | 111 ++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 19 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 99d1d3b5d..b97273176 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1,4 +1,5 @@ -// CODE here for your Lambda Classes +//Classes: + class Person{ constructor(attributes){ this.name = attributes.name, @@ -6,10 +7,12 @@ class Person{ 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 Person{ constructor(InstructorAttributes){ super(InstructorAttributes); @@ -21,12 +24,12 @@ class Instructor extends Person{ return `Today we are learning about ${this.subject}` } grade(_student, _object){ - return `${this.student.name} receives a perfect score on ${this.subject}`; + return `${this.student.name} receives a perfect score on ${this.subject}!`; } +} -} class Student extends Instructor{ constructor(StudentAttributes){ @@ -41,29 +44,99 @@ class Student extends Instructor{ PRAssignment(_name, _subject){ return `${this.student.name} has submitted a PR for ${this.subject}`; } - - } - - - - -} - class ProjectManager extends Student{ constructor(ProjectManagerAttributes){ super(ProjectManagerAttributes); - - - + this.gradClassName = ProjectManagerAttributes.gradClassName, + this.favInstructor = ProjectManagerAttributes.favInstructor + } + standUp(_slackChannel){ + return `${this.name} announces to ${this.channel}, @channel stand times!​​​​​`; + } + debugsCode(_object, _subject ){ + return `${this.name} debugs ${this.student.name}'s code on ${this.subject}`; } - - - - } +//______________________________________________________________________ +//instructors: + +const Jerry = new Instructor({ +name: 'Jerry', +location: 'Utah', +age: 42, +favLanguage: 'Java', +specialty: 'Computer Science Theory', +catchPhrase: `Love the whales` +}); + +const Aya = new Instructor({ + name: 'Aya', + location: 'Wisconsin', + age: 48, + favLanguage: 'C++', + specialty: 'devops', + catchPhrase: `I like cats` + }); + +//______________________________________________________________________ +//students: + + +const Jon = new Student({ + name: 'Jon', + location: 'Idaho', + age: 36, + previousBackground: `cook`, + className: `CS122`, + favSubjects: `front-end` + }); + +const Jeremy = new Student({ + name: 'Jeremy', + location: 'UK', + age: 22, + previousBackground: `college student`, + className: `CS125`, + favSubjects: `back-end` + }); + +//______________________________________________________________________ +//projectManagers: + +const Kate = new ProjectManager({ + name: 'Kate', + location: 'New Zealand', + age: 53, + gradClassName: 'Web1', + favInstructor: 'Aya' + }); + +const Kerin = new ProjectManager({ + name: 'Kerin', + location: 'Japan', + age: 37, + gradClassName: 'IOS12', + favInstructor: 'Jerry' + }); + +//______________________________________________________________________ +//console.logs for students: + +console.log(Jerry.speak()); +console.log(Aya.speak()); + +//______________________________________________________________________ +//console.logs for instructors: + + + + + +//______________________________________________________________________ +//console.logs for projectManagers: \ No newline at end of file From eaf084d152c8e6fb1f4b6015d64bc4ad7184454d Mon Sep 17 00:00:00 2001 From: miriam-sullivan Date: Thu, 19 Sep 2019 17:48:06 -0500 Subject: [PATCH 4/4] finished --- assignments/lambda-classes.js | 62 ++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index b97273176..f925cfb23 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -20,11 +20,11 @@ class Instructor extends Person{ this.favLanguage = InstructorAttributes.favLanguage, this.catchPhrase = InstructorAttributes.catchPhrase } - demo(_subject){ - return `Today we are learning about ${this.subject}` + demo(subject){ + return `Today we are learning about ${subject}.` } - grade(_student, _object){ - return `${this.student.name} receives a perfect score on ${this.subject}!`; + grade(student, subject){ + return `${student.name} receives a perfect score on ${subject}!`; } } @@ -41,8 +41,8 @@ class Student extends Instructor{ listsSubjects(){ return `${this.favSubjects}` } - PRAssignment(_name, _subject){ - return `${this.student.name} has submitted a PR for ${this.subject}`; + PRAssignment(student, subject){ + return `${student.name} has submitted a PR for ${subject}`; } } @@ -54,11 +54,11 @@ class ProjectManager extends Student{ this.gradClassName = ProjectManagerAttributes.gradClassName, this.favInstructor = ProjectManagerAttributes.favInstructor } - standUp(_slackChannel){ - return `${this.name} announces to ${this.channel}, @channel stand times!​​​​​`; + standUp(channel){ + return `${this.name} announces to ${channel}, @channel stand times!​​​​​`; } - debugsCode(_object, _subject ){ - return `${this.name} debugs ${this.student.name}'s code on ${this.subject}`; + debugsCode(student, subject ){ + return `${this.name} debugs ${student.name}'s code on ${subject}`; } } @@ -67,20 +67,20 @@ class ProjectManager extends Student{ //instructors: const Jerry = new Instructor({ -name: 'Jerry', -location: 'Utah', -age: 42, -favLanguage: 'Java', -specialty: 'Computer Science Theory', -catchPhrase: `Love the whales` -}); + name: 'Jerry', + location: 'Utah', + age: 42, + favLanguage: 'Java', + specialty: 'Computer Science Theory', + catchPhrase: `Love the whales` + }); const Aya = new Instructor({ name: 'Aya', location: 'Wisconsin', age: 48, favLanguage: 'C++', - specialty: 'devops', + specialty: 'DevOps', catchPhrase: `I like cats` }); @@ -89,13 +89,13 @@ const Aya = new Instructor({ const Jon = new Student({ - name: 'Jon', - location: 'Idaho', - age: 36, - previousBackground: `cook`, - className: `CS122`, - favSubjects: `front-end` - }); + name: 'Jon', + location: 'Idaho', + age: 36, + previousBackground: `cook`, + className: `CS122`, + favSubjects: `front-end` + }); const Jeremy = new Student({ name: 'Jeremy', @@ -125,17 +125,19 @@ const Kerin = new ProjectManager({ favInstructor: 'Jerry' }); + //______________________________________________________________________ -//console.logs for students: +//console.logs for instructors: console.log(Jerry.speak()); +console.log(Jerry.demo('math')); console.log(Aya.speak()); - +console.log(Aya.demo('science')); +console.log(Jerry.grade(Jon, 'Computer Science')) //______________________________________________________________________ -//console.logs for instructors: - - +//console.logs for students: +console.log(Jon.) //______________________________________________________________________