From 89138a4cfc93fee4a874d92106a13c15b71dbb6b Mon Sep 17 00:00:00 2001 From: "M.Real" Date: Thu, 24 May 2018 16:19:05 -0400 Subject: [PATCH 1/2] Almost ready to test lambda classes + stretch --- assignments/lambda-classes.js | 90 +++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 44 +++++++-------- 2 files changed, 112 insertions(+), 22 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..81c9c3f4f 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,91 @@ // 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 +} + speak(){ + console.log(`Hello my name is ${this.name}, I am from ${this.location}`); + } + +} + +class Instructor extends Person { + constructor(options){ + super(options); + this.specialty = options.specialty + this.favLanguage = options.favLanguage + this.catchPhrase = options.catchPhrase + } + + demo(subject){ + console.log(`Today we are learning about ${subject}`); + } + grade(student, subject){ + console.log(`${student.name} receives a perfect score on ${subject}`); + } + gradeAdjust(min, max){ + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random(student.grade) * (max - min + 1)) + min; + } +} +class Student extends Person { + constructor(traits){ + super(traits); + this.previousBackground = traits.previousBackground + this.className = traits.className + this.favSubjects = traits.favSubjects + } + + listsSubjects(){ + for(i=0;i 70){ + console.log(`Congratulations ${student.name}, you graduated!`) + } + else { + grade(student.name) + } + } +} + +class ProjectManagers extends Instructor { + constructor(descriptors){ + super(descriptors); + this.gradClassName = descriptors.gradClassName + this.favInstructor = descriptors.favInstructor + } + + standup(channel){ + console.log(`${name} announces to ${channel}, @channel standy times!`); + } + debugsCode(student, subject){ + console.log(`${name} debugs ${student.name}'s code on ${subject}`) + } +} + +console.log() +console.log() +console.log() +console.log() +console.log() +console.log() +console.log() +console.log() +console.log() +console.log() \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..04bf1295c 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,39 @@ // 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; } - -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; + destroy() { + return `Object was removed from the game.`; } -CharacterStats.prototype = Object.create(GameObject.prototype); +class CharacterStats extends GameObject { + constructor(characterStatsOptions) { + super(characterStatsOptions); + this.hp = characterStatsOptions.hp + this.name = characterStatsOptions.name +} -CharacterStats.prototype.takeDamage = function() { +takeDamage() { 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); +class Humanoid extends CharacterStats { + constructor(humanoidOptions) { + super(humanoidOptions); + this.faction = humanoidOptions.faction + this.weapons = humanoidOptions.weapons + this.language = humanoidOptions.language +} -Humanoid.prototype.greet = function() { + greet() { return `${this.name} offers a greeting in ${this.language}.`; -}; +} +} const mage = new Humanoid({ createdAt: new Date(), From 96b064b5c7d11e52a0c8b65af433ff61c29d080e Mon Sep 17 00:00:00 2001 From: "M.Real" Date: Thu, 24 May 2018 18:46:01 -0400 Subject: [PATCH 2/2] All done but graduate function, listsSubjects reading undefined --- assignments/lambda-classes.js | 129 +++++++++++++++++++++++------- assignments/prototype-refactor.js | 4 +- 2 files changed, 103 insertions(+), 30 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 81c9c3f4f..bab112a81 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -8,7 +8,7 @@ class Person { } speak(){ console.log(`Hello my name is ${this.name}, I am from ${this.location}`); - } +} } @@ -21,15 +21,15 @@ class Instructor extends Person { } demo(subject){ - console.log(`Today we are learning about ${subject}`); + return `Today we are learning about ${subject}`; } grade(student, subject){ - console.log(`${student.name} receives a perfect score on ${subject}`); + return `${student} receives a perfect score on ${subject}`; } - gradeAdjust(min, max){ + gradeChange(min, max){ min = Math.ceil(min); max = Math.floor(max); - return Math.floor(Math.random(student.grade) * (max - min + 1)) + min; + return Math.floor(Math.random(this.grade) * (max - min + 1)) + min; } } class Student extends Person { @@ -40,30 +40,29 @@ class Student extends Person { this.favSubjects = traits.favSubjects } - listsSubjects(){ - for(i=0;i 70){ - console.log(`Congratulations ${student.name}, you graduated!`) + if (this.grade > 70){ + console.log(`Congratulations ${this.name}, you graduated!`) } else { - grade(student.name) + console.log(this.grade); } } } - class ProjectManagers extends Instructor { constructor(descriptors){ super(descriptors); @@ -72,20 +71,94 @@ class ProjectManagers extends Instructor { } standup(channel){ - console.log(`${name} announces to ${channel}, @channel standy times!`); + return `${this.name} announces to ${channel}, @channel standy times!`; } debugsCode(student, subject){ - console.log(`${name} debugs ${student.name}'s code on ${subject}`) + return `${this.name} debugs ${student}'s code on ${subject}`; } } -console.log() -console.log() -console.log() -console.log() -console.log() -console.log() -console.log() -console.log() -console.log() -console.log() \ No newline at end of file +const Mike = new Student ({ + name: 'Mike', + age: 28, + location: 'Philadelphia, PA', + gender: 'M', + previousBackground: 'Covert Ops', + className: 'CS 11', + favSubjects:['JavaScript', 'CSS', 'Python'] +}); +const Todd = new Student ({ + name: 'Todd', + age: 34, + location: 'Albequerque, NM', + gender: 'M', + previousBackground: 'Accountant', + className: 'CS 10', + favSubjects:['Node', 'C++', 'Applied Cryptography'] +}); + +const Darrel = new Instructor ({ + name: 'Darrel', + age: 41, + location: 'Austin, TX', + gender: 'M', + specialty: 'Applied JavaScript', + favLanguage: 'Rust', + catchPhrase: 'Flippin heck!' +}); + +const Tracy = new Instructor ({ + name: 'Tracy', + age: 37, + location: 'Seattle, WA', + gender: 'F', + specialty: 'React', + favLanguage: 'Solidity', + catchPhrase: 'By golly!' +}); + +const Cheryl = new ProjectManagers ({ + name: 'Cheryl', + age: 51, + location: 'Buffalo, NY', + gender: 'F', + specialty: 'Node', + favLanguage: 'Python', + catchPhrase: 'Bring the ruckus!', + gradClassName: 'Aristocrats', + favInstructor: 'Patrick' +}); + +const David = new ProjectManagers ({ + name: 'David', + age: 70, + location: 'Denver, CO', + gender: 'M', + specialty: 'R', + favLanguage: 'JavaScript', + catchPhrase: 'What was that?', + gradClassName: 'Gentlefolks', + favInstructor: 'Josh' +}); + + +console.log(Mike.previousBackground); +console.log(Todd.className); +console.log(Mike.favSubjects); +console.log(Todd.listsSubjects()); //? +console.log(Mike.PRAssignment('value')); +console.log(Mike.sprintChallenge('whatever')); +console.log(Darrel.catchPhrase); +console.log(Darrel.specialty); +console.log(Tracy.favLanguage); +console.log(Tracy.demo('C')); +console.log(Tracy.grade('Jeff', 'C++')); +console.log(Cheryl.favInstructor); //? +console.log(Cheryl.demo('thing')); +console.log(Cheryl.grade('Cheryl' ,'R')); //? +console.log(David.gradClassName); +console.log(David.standup('CS11')); +console.log(David.debugsCode('Alan', 'HTML')); +console.log(Mike.gradeAdjust()); +console.log(Todd.graduate()); +console.log(Darrel.gradeChange(70,80)); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 04bf1295c..3551f30e5 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -10,8 +10,8 @@ class GameObject { destroy() { return `Object was removed from the game.`; } - -class CharacterStats extends GameObject { +} + class CharacterStats extends GameObject { constructor(characterStatsOptions) { super(characterStatsOptions); this.hp = characterStatsOptions.hp