From 145369cd11e6c5186f93581ad1fdec053ba2d2de Mon Sep 17 00:00:00 2001 From: Katie Gorbell Date: Thu, 24 May 2018 16:27:17 -0500 Subject: [PATCH 1/3] initial pr --- assignments/prototype-refactor.js | 55 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..baa55d744 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,40 +2,41 @@ // Today 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(options) { - this.createdAt = options.createdAt; - this.dimensions = options.dimensions; +class GameObject { + constructor(options) { + this. createdAt = options.createdAt; + this.dimensions = options.dimensions; + } + destroy() { + return `${this.name} was removed from the game.`; + } } -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; -}; - -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); - this.hp = characterStatsOptions.hp; - this.name = characterStatsOptions.name; +class CharacterStats extends GameObject { + constructor(characterStatsOptions) { + super(characterStatsOptions); + this.hp = characterStatsOptions.hp; + this.name = characterStatsOptions.name; + } + takeDamage() { + return `${this.name} took damage.`; + } } -CharacterStats.prototype = Object.create(GameObject.prototype); - -CharacterStats.prototype.takeDamage = function() { - return `${this.name} took damage.`; -}; +// CharacterStats.prototype = Object.create(GameObject.prototype); -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); - this.faction = humanoidOptions.faction; - this.weapons = humanoidOptions.weapons; - this.language = humanoidOptions.language; +class Humanoid extends CharacterStats { + constructor(humanoidOptions) { + super(humanoidOptions); + this.faction = humanoidOptions.faction; + this.weapons = humanoidOptions.weapons; + this.language = humanoidOptions.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}.`; -}; - const mage = new Humanoid({ createdAt: new Date(), dimensions: { From 0a4edfc6940b5a80bd94fef54e4c1b42ce5df42b Mon Sep 17 00:00:00 2001 From: Katie Gorbell Date: Thu, 24 May 2018 17:28:34 -0500 Subject: [PATCH 2/3] built Lambda-classes Constructors with methods --- assignments/lambda-classes.js | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..f1f3f5123 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,68 @@ // CODE here for your Lambda Classes +class Person { + constructor(attributes) { + this.name = attributes.name; + this.age = attributes.age; + this.location = attributes.location; + this.gender = attributes.gender; + } + introduce() { + return `Hello, my name is ${this.name}, I am from ${this.location}.` + } +} + +class Instructor extends Person{ + constructor(instructorAttrs) { + super(instructorAttrs); + this.specialty = instructorAttrs.specialty; + this.favLanguage = instructorAttrs.favLanguage; + this.catchPhrase = instructorAttrs.catchPhrase; + } + demo(subject) { + return `today we are learning about ${subject}.` + } + grade(student, subject) { + return `${student.name} receives a perfect score on ${subject} ` + } +} + +class Student extends Person { + constructor(studentAttrs) { + super(studentAttrs); + this.previousBackground = studentAttrs.previousBackground; + this.className = studentAttrs.className; + this.favSubjects = studentAttrs.favSubjects; + } + listsSubjects(arr) { + return `${this.favSubjects};` + } + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}`; + } + sprintChallenge(subject) { + return `${this.name} has begun a sprint challenge on ${subject}`; + } +} + +class ProjectManager extends Instructor { + constructor(PMAttrs) { + super(PMAttrs); + this.gradClassName = PMAttrs.gradClassName; + this.favInstructor = PMAttrs.favInstructor; + } + standUp(slackChannel) { + return `${this.name} announces to ${slackChannel}, @channel standy time!`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}`; + } +} + + +console.log(Josh.demo('whatevs')); +console.log(Josh.grade(Katie, 'project')); +console.log(Katie.listsSubjects(this.favSubjects)); +console.log(Katie.PRAssignment('LESS')); +console.log(Katie.sprintChallenge('JavaScript')); +console.log(Holly.standUp('CS11_Holly')); +console.log(Holly.debugsCode(Katie, 'CSS')); From c23d670b60bc72e0207c432ea60f65f306d5842b Mon Sep 17 00:00:00 2001 From: Katie Gorbell Date: Thu, 24 May 2018 19:02:23 -0500 Subject: [PATCH 3/3] added objects --- assignments/lambda-classes.js | 70 +++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index f1f3f5123..04290f20f 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -26,6 +26,28 @@ class Instructor extends Person{ } } +const Gene = new Instructor({ + name: 'Gene Cousineau', + age: 65, + location: 'L.A.', + gender: 'M', + specialty: 'Teaching acting', + favLanguage: 'the language of Theatre', + catchPhrase: 'You\'re never going to see the inside of this acting class again!' +}); + +const Fuches = new Instructor({ + name: 'Fuches', + age: 58, + location: 'L.A.', + gender: 'M', + specialty: 'handling the "business"', + favLanguage: 'money', + catchPhrase: 'BARRY, YOU\'RE ALIVE!', +}) + + + class Student extends Person { constructor(studentAttrs) { super(studentAttrs); @@ -34,7 +56,7 @@ class Student extends Person { this.favSubjects = studentAttrs.favSubjects; } listsSubjects(arr) { - return `${this.favSubjects};` + return `${this.favSubjects}; ` } PRAssignment(subject) { return `${this.name} has submitted a PR for ${subject}`; @@ -44,6 +66,26 @@ class Student extends Person { } } +const Barry = new Student({ + name: 'Barry Berkman', + age: 35, + location: 'L.A.', + gender: 'M', + previousBackground: 'Hitman', + className: 'Cousineau\'s Acting Class', + favSubjects: ['Acting', 'Shooting guns', 'daydreaming about Sally'], +}); + +const Sally = new Student({ + name: 'Sally Reed', + age: 29, + location: 'L.A.', + gender: 'F', + previousBackground: 'Acting', + className: 'Cousineau\'s Acting Class', + favSubjects: ['Acting', 'Auditioning'], +}) + class ProjectManager extends Instructor { constructor(PMAttrs) { super(PMAttrs); @@ -58,11 +100,23 @@ class ProjectManager extends Instructor { } } +const Hank = new ProjectManager ({ + name: 'Noho Hank', + age: 32, + location: 'L.A.', + gender: 'M', + specialty: 'being a Mobster', + favLanguage: 'Chechen', + catchPhrase: 'We will find you, and we will kill you.', + gradClassName: 'right-hand man', + favInstructor: 'Goran Pazar', +}) + -console.log(Josh.demo('whatevs')); -console.log(Josh.grade(Katie, 'project')); -console.log(Katie.listsSubjects(this.favSubjects)); -console.log(Katie.PRAssignment('LESS')); -console.log(Katie.sprintChallenge('JavaScript')); -console.log(Holly.standUp('CS11_Holly')); -console.log(Holly.debugsCode(Katie, 'CSS')); +console.log(Gene.demo('MacBeth')); +console.log(Fuches.grade(Barry, 'Killing the target')); +console.log(Barry.listsSubjects(this.favSubjects)); +console.log(Sally.PRAssignment('playing MacBeth')); +console.log(Barry.sprintChallenge('stopping Chris from saying anything')); +console.log(Hank.standUp('the mobsters')); +console.log(Hank.debugsCode(Barry, 'CSS'));