From 5fb0ac3f49733cad307210c8ba050b250b6e7fb5 Mon Sep 17 00:00:00 2001 From: Mark Hong Date: Thu, 24 May 2018 17:19:43 -0400 Subject: [PATCH 1/3] done with prototype refactor --- assignments/lambda-classes.js | 18 +++++++++ assignments/prototype-refactor.js | 61 +++++++++++++++---------------- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..e38416de5 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,19 @@ // CODE here for your Lambda Classes + +class Person { + constructor(traits) { + this.name = traits.name; + this.age = traits.age; + this.location = traits.location; + this.gender = traits.gender; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}.` + } +} + +class Instructor extends Person { + constructor() { + + } +} \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..b79009efa 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,38 @@ // 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 -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; -}; +class CharacterStats extends GameObject { + constructor(charStatsOptions) { + super(charStatsOptions); + this.hp = charStatsOptions.hp; + this.name = charStatsOptions.name; + } + takeDamage() { + return `${this.name} took damage.`; + } +} //CharacterStats -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); - 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}.`; -}; +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 const mage = new Humanoid({ createdAt: new Date(), From 5fdeae5d0d502f5d9e702f16481f28f3c1b349c3 Mon Sep 17 00:00:00 2001 From: Mark Hong Date: Thu, 24 May 2018 18:12:21 -0400 Subject: [PATCH 2/3] done with lambda-classes prior to stretching --- assignments/lambda-classes.js | 98 +++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index e38416de5..630aa6e06 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -8,12 +8,102 @@ class Person { this.gender = traits.gender; } speak() { - return `Hello my name is ${this.name}, I am from ${this.location}.` + return `Hello, my name is ${this.name}, and I am from ${this.location}.` } } class Instructor extends Person { - constructor() { - + constructor(teachTraits) { + super(teachTraits); + this.specialty = teachTraits.specialty; + this.favLanguage = teachTraits.favLanguage; + this.catchPhrase = teachTraits.catchPhrase; } -} \ No newline at end of file + demo(subject) { + if (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(neoTraits) { + super(neoTraits); + this.previousBackground = neoTraits.previousBackground; + this.className = neoTraits.className; + this.favSubjects = neoTraits.favSubjects; + } + listsSubjects() { + let list = this.favSubjects.join(', '); + return `${this.name}'s favorite subjects are: ${list}.` + } + 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(pmTraits) { + super(pmTraits); + this.gradClassName = pmTraits.gradClassName; + this.favInstructor = pmTraits.favInstructor; + } + standUp(channel) { + return `${this.name} announces to ${channel}: Hey @${channel}, it's standup time!`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}.`; + } +} + +const beatrix = new Person({ + name: 'Beatrix', + age: 28, + location: 'Alexandria', + gender: 'Female', +}); + +const bigBoss = new Instructor({ + name: 'John', + age: 83, + location: 'Unknown, USA', + gender: 'Male', + specialty: 'Covert Operations (and also redux)', + favLanguage: 'CQC', + catchPhrase: 'We are soldiers without borders, our purpose defined by the era we live in.' +}); + +const mark = new Student({ + name: 'Mark', + age: 28, + location: 'Florida', + gender: 'Male', + previousBackground: 'Jack-of-all-trades', + className: 'CS11', + favSubjects: ['Digital Art', 'JavaScript', 'UI Design', 'UX Heuristics & Theorycrafting', 'Game Design', 'Music'] +}); + +const hiawatha = new ProjectManager({ + name: 'Hiawatha', + age: 99, + location: 'The Land Before Time', + gender: 'Male', + gradClassName: 'CS00: Reloaded', + favInstructor: 'Merlin the Legendary Wizard' +}) + +console.log(beatrix.speak()); +console.log(bigBoss.demo(bigBoss.favLanguage)); +console.log(bigBoss.grade(beatrix,bigBoss.favLanguage)); +console.log(mark.listsSubjects()); +console.log(mark.PRAssignment(mark.favSubjects[2])); +console.log(mark.sprintChallenge(mark.favSubjects[4])); +console.log(hiawatha.standUp(`cs11`)); +console.log(hiawatha.debugsCode(mark,mark.favSubjects[1])); + From d00d472fe8343654ea7f7cb9cfa7ade18dea8656 Mon Sep 17 00:00:00 2001 From: Mark Hong Date: Thu, 24 May 2018 18:48:38 -0400 Subject: [PATCH 3/3] messing around with math and grades --- assignments/lambda-classes.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 630aa6e06..7c6dbab60 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -27,6 +27,15 @@ class Instructor extends Person { grade(student, subject) { return `${student.name} receives a perfect score on ${subject}!`; } + tutor(student) { + let grade = student.grade; + let randomNum = Math.floor(Math.random()*24); + let upOrDown = Math.random() < 0.5 ? -1 : 1; + let scoreChange = randomNum * upOrDown; + if (grade) { + return grade + scoreChange; + } + } } class Student extends Person { @@ -35,6 +44,7 @@ class Student extends Person { this.previousBackground = neoTraits.previousBackground; this.className = neoTraits.className; this.favSubjects = neoTraits.favSubjects; + this.grade = neoTraits.grade; } listsSubjects() { let list = this.favSubjects.join(', '); @@ -46,6 +56,13 @@ class Student extends Person { sprintChallenge(subject) { return `${this.name} has begun a sprint challenge on ${subject}.` } + graduate() { + if (this.grade > 70) { + let finalGrade = this.grade; + return `Congratulations! You've passed our examinations with a score of ${finalGrade}. This means that you're ready to graduate! Go forth and prosper with code.` + } + return `${this.name}'s score of ${this.grade} is not enough to graduate yet. Keep studying!` + } } class ProjectManager extends Instructor { @@ -86,7 +103,8 @@ const mark = new Student({ gender: 'Male', previousBackground: 'Jack-of-all-trades', className: 'CS11', - favSubjects: ['Digital Art', 'JavaScript', 'UI Design', 'UX Heuristics & Theorycrafting', 'Game Design', 'Music'] + favSubjects: ['Digital Art', 'JavaScript', 'UI Design', 'UX Heuristics & Theorycrafting', 'Game Design', 'Music'], + grade: Math.floor(Math.random() * 10) + 65 }); const hiawatha = new ProjectManager({ @@ -107,3 +125,13 @@ console.log(mark.sprintChallenge(mark.favSubjects[4])); console.log(hiawatha.standUp(`cs11`)); console.log(hiawatha.debugsCode(mark,mark.favSubjects[1])); +console.log(mark.grade); +console.log(hiawatha.tutor(mark)); +console.log(mark.graduate()); + + + + + + +