From e2ad5a685f9a83ec389e0671209221d6eb6d61b3 Mon Sep 17 00:00:00 2001 From: Eric B Date: Thu, 24 May 2018 17:37:23 -0500 Subject: [PATCH 1/2] Initial Push --- assignments/lambda-classes.js | 111 ++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 62 ++++++++++++----- 2 files changed, 155 insertions(+), 18 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..379d17538 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,112 @@ // CODE here for your Lambda Classes + + +class Person { + constructor(persProps) { + this.name = persProps.name; + this.age = persProps.age; + this.location = persProps.location + this.gender = persProps.gender; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}`; + } +} + + +class Instructor extends Person { + constructor(instructProps) { + super(instructProps); + this.specialty = instructProps.specialty; + this.favLanguage = instructProps.favLanguage; + this.catchPhrase = instructProps.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(studProps) { + super(studProps); + this.previousBackground = studProps.previousBackground; + this.className = studProps.className; + this.favSubjects = studProps.favSubjects; + } + listSubjects() { + this.favSubjects.forEach(function(subject){ + return subject; + }) + } + PRAssignment(subject) { + console.log(`${this.student.name} has submitted a PR for ${subject}`) + } + sprintChallenge(subject) { + console.log(`${student.name} has begun sprint challenge on ${subject}`) + } +} + + +class projectManager extends Instructor { + constructor(projmanProps) { + super(projmanProps); + this.gradClassName = projmanProps.gradClassName; + this.favInstructor = projmanProps.favInstructor; + } + standUp(channel) { + console.log(`${this.name} announces to ${channel}, @channel standy times!`) + } + debugsCode(student, subject) { + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`) + } +} + + +const bob = new Person({ + name: "Bob", + age: 30, + location: "Iowa" +}) + +const megan = new Person({ + name: "Megan", + age: 24, + location: "South Africa" +}) + + +const josh = new Instructor({ + name: "Josh", + age: 30, + location: "Silicon Heaven, Utah", + specialty: "Front End", + favLanguage: "JavaScript", + catchPhrase: "Call me Uncle Josh", + +}) + +const ben = new projectManager ({ + name: "Ben", + age: 27, + location: "Heavenly Mexico", + specialty: "React Awesomeness", + favLanguage: "Spanish", + catchPhrase: "I'm heading to Denver to relax.", + gradClassName: "CS205", + favInstructor: "Ben Nelson" +}) + +const kelley = new Student ({ + name: "Kelley", + age: 25, + location: "New Orleans", + previousBackground: "Secretary", + className: "CS11", + favSubjects: ["Anatomy", "Computer Science", "JavaScript"] +}) + + +console.log(kelley.listSubjects()); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..fd7fdd5b1 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,65 @@ // 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) { +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); +class CharacterStats extends GameObject { + constructor(characterStatsOptions) { + super(characterStatsOptions) this.hp = characterStatsOptions.hp; - this.name = characterStatsOptions.name; + 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.`; -}; +// function CharacterStats(characterStatsOptions) { +// GameObject.call(this, characterStatsOptions); +// this.hp = characterStatsOptions.hp; +// this.name = characterStatsOptions.name; +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); + +// CharacterStats.prototype.takeDamage = function() { +// return `${this.name} took damage.`; +// }; -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); +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}.`; -}; +// (humanoidOptions) { +// CharacterStats.call(this, humanoidOptions); +// this.faction = humanoidOptions.faction; +// this.weapons = humanoidOptions.weapons; +// this.language = humanoidOptions.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(), From 04d25437354db539189a87d5a30cbee7e66bceda Mon Sep 17 00:00:00 2001 From: Eric B Date: Thu, 24 May 2018 18:25:51 -0500 Subject: [PATCH 2/2] Added more objects & corrected a template literal ref --- assignments/lambda-classes.js | 44 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 379d17538..8237c6060 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -22,10 +22,10 @@ class Instructor extends Person { this.catchPhrase = instructProps.catchPhrase; } demo(subject) { - return `Today we are learning about ${subject}.` + console.log(`Today we are learning about ${subject}.`); } grade(student, subject) { - return `${student.name} receives a perfect score on ${subject}`; + console.log(`${student.name} receives a perfect score on ${subject}`); } } @@ -38,14 +38,14 @@ class Student extends Person { } listSubjects() { this.favSubjects.forEach(function(subject){ - return subject; + console.log(subject); }) } PRAssignment(subject) { - console.log(`${this.student.name} has submitted a PR for ${subject}`) + console.log(`${this.name} has submitted a PR for ${subject}`) } sprintChallenge(subject) { - console.log(`${student.name} has begun sprint challenge on ${subject}`) + console.log(`${this.name} has begun sprint challenge on ${subject}`) } } @@ -79,7 +79,7 @@ const megan = new Person({ const josh = new Instructor({ - name: "Josh", + name: "Josh Knell", age: 30, location: "Silicon Heaven, Utah", specialty: "Front End", @@ -89,7 +89,7 @@ const josh = new Instructor({ }) const ben = new projectManager ({ - name: "Ben", + name: "Ben Campbell", age: 27, location: "Heavenly Mexico", specialty: "React Awesomeness", @@ -108,5 +108,33 @@ const kelley = new Student ({ favSubjects: ["Anatomy", "Computer Science", "JavaScript"] }) +const ryan = new Instructor({ + name: "Ryan", + age: 30, + location: "Somewhere, CA", + specialty: "codin'", + favLanguage: "JavaScript", + catchPhrase: "...I have a cool red beard?", + +}) + +const perry = new projectManager ({ + name: "perry", + age: 49, + location: "New York", + specialty: "HTML", + favLanguage: "English", + catchPhrase: "Don't get discouraged", + gradClassName: "CS20", + favInstructor: "Josh" +}) + +const eric = new Student ({ + name: "Eric", + age: 29, + location: "Minnesota", + previousBackground: "Punk Rocker", + className: "CS -12", + favSubjects: ["Anatomy", "Computer Science", "Calculus", "Taekwondo"] +}) -console.log(kelley.listSubjects()); \ No newline at end of file