From 048d5f7aa8268f295b13c4b560020e2066a99c6e Mon Sep 17 00:00:00 2001 From: wade coplen Date: Thu, 10 Oct 2019 20:25:22 -0700 Subject: [PATCH 1/3] lamba-class setup classes and objects --- assignments/prototype-refactor.js | 129 +++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..6aa90dd66 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,4 +1,4 @@ -/* +/* Prototype Refactor @@ -6,4 +6,131 @@ 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. +class Parent { + constructor(attributes){ + this.newAge = attributes.age; + this.newName = attributes.name; + this.newLocation = attributes.location; + this.newPhrase= attributes.phrase; + } + //Methods + speak () { + return `${this.newName} says ${this.newPhrase}`; + } + location() { + return `${this.newName} says ${this.newPhrase}`; + } + }//Parent + + + class Child extends Parent{ + constructor(childAttributes){ + super(childAtttributes); + this.toy = childAttributes.toy; + } + speak () { + return `${this.newName} says ${this.newPhrase}`; + console.log(speak()); + + } + + }//Child +-------------------------------------------------------------------- */ +class Parent { + GameObject(objects) { + this.createdAt = objects.createdAt; + this.name = objects.name; + this.dimensions = objects.dimensions; + } + destroy() { + return `${this.name} was removed from the game.`; + } + +} + +class Child extends Parent { + CharacterStats(stats) { + super(stats); + this.healthPoints = stats.healthPoints; + }; + + takeDamage() { + return `${this.name} took damage.`; + } +} + + + +class grandchild extends Child { + Humanoid(attributes) { + super(attributes); + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + greet() { + return `${this.name} offers a greeting in ${this.language}`; + } +} + +// 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 ee002915a53e3f4d3c61c3b9303babd5b5dcc213 Mon Sep 17 00:00:00 2001 From: wade coplen Date: Thu, 10 Oct 2019 22:23:21 -0700 Subject: [PATCH 2/3] add values to objects --- assignments/lambda-classes.js | 159 ++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..c7543f5e5 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,160 @@ // CODE here for your Lambda Classes +//Parent +class Parent { + person(attributes) { + this.newName = attributes.name; + this.newAge = attributes.age; + this.newLocation = attributes.location; + } + +//Method + speak() { + return `Hell my name is ${this.name}, I am from ${this.location}.`; + console.log(speak()); + } +} +//--------------------------- +//Child +class Child extends Person { + instructors(resume) { + super(); + this.newSpecialty = resume.specialty; + this.newfavLanguage = resume.favLanguage; + this.newcatchPhrase = resume.catchPhrase; + + } + +//Method + demo(subject) { + return `Today we are learning about ${subject}.`; + } + grade() { + return `${student.name}receives a perfect score on ${subject}.`; + } +} +//--------------------------- +//Grandchild +class Grandchild extends Child { + students(report) { + this.newPreviousBackground = report.previousBackground; + this.newClassName = report.className; + this.newFavSubjects = report.favSubjects; + super(report); + } +} +//Methods + listSubjects() {// a method that logs out all of the student's favoriteSubjects one by one. + return `${student.name}receives a perfect score on ${subject}.`; + } + PRAssignment() {//a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject} + return `${student.name}receives a perfect score on ${subject}.`; + } + sprintChallenge() {//similar to PRAssignment but logs out student.name has begun sprint challenge on {subject} + return ``; + } +//--------------------------- +//GreatGrandchild +class GreatGrandchild extends GrandChild { + projectManagers(personal) { + this.newstandUp = personal.standup; + this.newFavInstructor = personal.favInstructor; + super(personal); + } + +//Method + standUp() {//a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​ + return ``; + } + debugsCodes() {//a method that takes in a student object and a subject and logs out {name} debugs {student.name}'s code on {subject} + return ``; + } +} + + + + + +//----Objects==== +//----Person------ +//1. +const firstPerson = new person({ + name: 'Gildo', + age: 11, + location: 'New Brunswick' +}); + +//2. +const secondPerson = new person({ + name: 'Galarny', + age: 13, + location: 'San Salvador', + }); +const thirdPerson = new person({ + name: 'Beckwith', + age: 26, + location: 'Calgary' + }); + + +//----- Instructor ------ +//1. +const firstInstructor = new instructor({ + specialty: 'History', + favLanguage: 'Dothraky', + catchPhrase: 'You know nuthin' +}); + +//2. +const secondInstructor = new instructor({ + specialty: 'Alchemy' + favLanguage: 'Elvin', + catchPhrase: 'Tu-wotha', +}); + + +//3. +const thirdInstructor = new instructor({ + specialty: 'metalurgy' + favLanguage: 'muckduck', + catchPhrase: 'All hands in the pot', +}); + +//---- Students ----- +//1. +const firstStudent = new students({ + previousBackground: '', + className: , + favSubjects: '', +}); + +//2. +const d = new students({ + previousBackground: '', + className: , + favSubjects: '', +}); + +//3. +const d = new students({ + previousBackground: '', + className: , + favSubjects: '', +}); +//---- PM's ------ +//1. +const g = new projectManagers({ + standUp: '', + favInstructor: , +}); + +//2. +const g = new projectManagers({ + standUp: '', + favInstructor: , +}); + +//3. +const g = new projectManagers({ + standUp: '', + favInstructor: , +}); From 2ba390d78edd030657674cbcc5618bd132e00df3 Mon Sep 17 00:00:00 2001 From: wade coplen Date: Fri, 11 Oct 2019 23:14:51 -0700 Subject: [PATCH 3/3] further --- assignments/lambda-classes.js | 144 ++++++++++++++++-------------- assignments/prototype-refactor.js | 27 +++--- 2 files changed, 93 insertions(+), 78 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index c7543f5e5..7d4138eeb 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1,71 +1,85 @@ // CODE here for your Lambda Classes //Parent class Parent { - person(attributes) { + constructor(attributes) { this.newName = attributes.name; this.newAge = attributes.age; this.newLocation = attributes.location; - } + } //Method - speak() { - return `Hell my name is ${this.name}, I am from ${this.location}.`; + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}.`; console.log(speak()); } } //--------------------------- //Child -class Child extends Person { - instructors(resume) { - super(); +class Child extends Parent { + constructor(resume) { + super(resume); this.newSpecialty = resume.specialty; this.newfavLanguage = resume.favLanguage; this.newcatchPhrase = resume.catchPhrase; - } + } -//Method - demo(subject) { +//Methods + demo(subject) { return `Today we are learning about ${subject}.`; - } - grade() { - return `${student.name}receives a perfect score on ${subject}.`; + console.log(demo(subject)); + } -} + + grade(student, subject) { + return `Hello ${student.name}receives a perfect score on ${subject}.`; + console.log(grade('Kara','hello')) + } + +} + + + //--------------------------- //Grandchild -class Grandchild extends Child { - students(report) { +class GrandChild extends Child { + constructor(report) { + super(report); this.newPreviousBackground = report.previousBackground; this.newClassName = report.className; this.newFavSubjects = report.favSubjects; - super(report); + } -} + //Methods - listSubjects() {// a method that logs out all of the student's favoriteSubjects one by one. - return `${student.name}receives a perfect score on ${subject}.`; - } + listSubjects(student, favSubjects) {// a method that logs out all of the student's favoriteSubjects one by one. + return `${student.name}receives a perfect score on ${this.favSubjects}.`; + console.log(listSubjects()); + } PRAssignment() {//a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject} - return `${student.name}receives a perfect score on ${subject}.`; + return `${student.name}receives a perfect score on ${subject}.`; + console.log(PRAssignment()); } - sprintChallenge() {//similar to PRAssignment but logs out student.name has begun sprint challenge on {subject} - return ``; - } + sprintChallenge() {//similar to PRAssignment but logs out student.name has begun sprint challenge on {subject} + return ``; + } +} + //--------------------------- //GreatGrandchild class GreatGrandchild extends GrandChild { - projectManagers(personal) { + constructor(personal) { + super(personal); this.newstandUp = personal.standup; this.newFavInstructor = personal.favInstructor; - super(personal); + } //Method - standUp() {//a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​ - return ``; - } - debugsCodes() {//a method that takes in a student object and a subject and logs out {name} debugs {student.name}'s code on {subject} + standUp() {//a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​ + return ``; + } + debugsCodes(student, subject) {//a method that takes in a student object and a subject and logs out {name} debugs {student.name}'s code on {subject} return ``; } } @@ -75,86 +89,86 @@ class GreatGrandchild extends GrandChild { //----Objects==== -//----Person------ +//----Parent------ //1. -const firstPerson = new person({ +const firstPerson = new Parent({ name: 'Gildo', age: 11, location: 'New Brunswick' }); //2. -const secondPerson = new person({ +const secondPerson = new Parent({ name: 'Galarny', age: 13, location: 'San Salvador', }); -const thirdPerson = new person({ +const thirdPerson = new Parent({ name: 'Beckwith', age: 26, location: 'Calgary' }); -//----- Instructor ------ +//----- Child ------ //1. -const firstInstructor = new instructor({ +const firstInstructor = new Child({ specialty: 'History', favLanguage: 'Dothraky', catchPhrase: 'You know nuthin' }); //2. -const secondInstructor = new instructor({ - specialty: 'Alchemy' +const secondInstructor = new Child({ + specialty: 'Alchemy', favLanguage: 'Elvin', - catchPhrase: 'Tu-wotha', + catchPhrase: 'Tu-wotha' }); //3. -const thirdInstructor = new instructor({ - specialty: 'metalurgy' +const thirdInstructor = new Child({ + specialty: 'metalurgy', favLanguage: 'muckduck', catchPhrase: 'All hands in the pot', }); -//---- Students ----- +//---- Grandchild ----- //1. -const firstStudent = new students({ - previousBackground: '', - className: , - favSubjects: '', +const firstStudent = new GrandChild({ + previousBackground: 'Detroit auto worker', + className: 'webpt11' , + favSubjects: ['javascript', 'html', 'css'], }); //2. -const d = new students({ - previousBackground: '', - className: , - favSubjects: '', +const d = new GrandChild({ + previousBackground: 'coal miner', + className: 'webpt11', + favSubjects: ['javascript', 'html', 'css'] }); //3. -const d = new students({ - previousBackground: '', - className: , - favSubjects: '', +const z = new GrandChild({ + previousBackground: 'truck driver', + className: 'webpt11', + favSubjects: ['javascript', 'html', 'css'], }); -//---- PM's ------ +//---- Great Grand Child ------ //1. -const g = new projectManagers({ - standUp: '', - favInstructor: , +const g = new GreatGrandchild({ + gradClassName: 'webpt11', + favInstructor: 'Josh Knell', }); //2. -const g = new projectManagers({ - standUp: '', - favInstructor: , +const y = new GreatGrandchild({ + gradClassName: 'webpt11', + favInstructor: 'Josh Knell', }); //3. -const g = new projectManagers({ - standUp: '', - favInstructor: , +const m = new GreatGrandchild({ + gradClassName: 'webpt11', + favInstructor: 'Josh Knell', }); diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 6aa90dd66..b1e995980 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -37,20 +37,21 @@ class Parent { }//Child -------------------------------------------------------------------- */ -class Parent { - GameObject(objects) { - this.createdAt = objects.createdAt; - this.name = objects.name; - this.dimensions = objects.dimensions; - } - destroy() { - return `${this.name} was removed from the game.`; +class GameObject { + constructor(objects) { + this.createdAt = objects.createdAt; + this.name = objects.name; + this.dimensions = objects.dimensions; + } + destroy() { + return `${this.name} was removed from the game.`; + } -} +} -class Child extends Parent { - CharacterStats(stats) { +class CharacterStats extends GameObject{ + constructor(stats) { super(stats); this.healthPoints = stats.healthPoints; }; @@ -62,8 +63,8 @@ class Child extends Parent { -class grandchild extends Child { - Humanoid(attributes) { +class Humanoid extends CharacterStats{ + constructor(attributes) { super(attributes); this.team = attributes.team; this.weapons = attributes.weapons;