From 71a14af5f416bc4d626e865b7ae8e2be7390552b Mon Sep 17 00:00:00 2001 From: Greg Hayes Date: Thu, 19 Sep 2019 18:27:22 -0500 Subject: [PATCH 1/4] Initial commit, converted prototypes to classes --- assignments/prototype-refactor.js | 136 ++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..b65956975 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,139 @@ 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. */ + +/* + === GameObject === + * createdAt + * name + * dimensions (These represent the character's size in the video game) + * destroy() // prototype method that returns: `${this.name} was removed from the game.` + * +*/ +class GameObject { + constructor(attribute) { + this.createdAt = attribute.createdAt; + this.name = attribute.name; + this.dimensions = attribute.dimensions; + } // closes constructor + // methods go here + destroy() { + return `${this.name} was removed from the game.`; + } +} +/* + === CharacterStats === + * healthPoints + * takeDamage() // prototype method -> returns the string ' took damage.' + * should inherit destroy() from GameObject's prototype + */ +class CharacterStats extends GameObject { + constructor(stats) { + super(stats); + this.healthPoints = stats.healthPoints; + } + takeDamage() { + return `${this.name} took damage.`; + } +} + +/* + === Humanoid (Having an appearance or character resembling that of a human.) === + * team + * weapons + * language + * greet() // prototype method -> returns the string ' offers a greeting in .' + * should inherit destroy() from GameObject through CharacterStats + * should inherit takeDamage() from CharacterStats + */ + +class Humanoid extends CharacterStats { + constructor(profile) { + super(profile); + this.team = profile.team; + this.weapons = profile.weapons; + this.language = profile.language; + } + greet() { + return `${this.name} offers a greeting in ${this.language}.`; + } +} + +// function Humanoid(profile) { +// CharacterStats.call(this, profile); +// this.team = profile.team; +// this.weapons = profile.weapons; +// this.language = profile.language; + +// // *** Again abstracting with a prototype below***// +// // this.greet = function() { +// // return `${this.newName} offers a greeting in ${this.newLanguage}.`; +// // }; +// } + +// //Object.create() allows the constructor function to see/inherit a parent function +// Humanoid.prototype = Object.create(CharacterStats.prototype); + +// Humanoid.prototype.greet = function() { +// return `${this.newName} offers a greeting in ${this.newLanguage}.`; +// }; +/* + * Inheritance chain: GameObject -> CharacterStats -> Humanoid + * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. + * Instances of CharacterStats should have all of the same properties as GameObject. + */ + +// 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 42b3beb8aca7b737e287825168a9118cc021e66e Mon Sep 17 00:00:00 2001 From: Greg Hayes Date: Thu, 19 Sep 2019 23:57:41 -0500 Subject: [PATCH 2/4] Created constructor classes --- assignments/lambda-classes.js | 52 +++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 21 ++----------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..5ce5653f6 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,53 @@ // CODE here for your Lambda Classes + +class Person { + constructor(attribute) { + this.name = attribute.name; + this.age = attribute.age; + this.location = attribute.location; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}. `; + } +} + +class Instructor extends Person { + constructor(attribute) { + this.specialty = attribute.specialty; + this.favLanguage = attribute.favLanguage; + this.catchPhrase = attribute.catchPhrase; + } + demo(subject) { + return `Today we are learning about ${this.subject}.`; + } + grade(student, subject) { + return `${student.name} receives a perfect score on ${this.subject}!`; + } +} + +class Student extends Person { + constructor(attribute) { + this.previousBackground = attribute.previousBackground; + this.className = attribute.className; + this.favSubjects = attribute.favSubjects; + } + listsSubjects(favSubjects) { + return this.favSubjects; + } + PRAssignment(subject) { + return `${this.name} has submitted a PR Assignment for ${subject}.`; + } +} + +class ProjectManager extends Instructor { + constructor(attribute) { + this.gradClassName = attribute.gradClassName; + this.favInstructor = attribute.favIntructor; + } + standUp(channel) { + return `${this.name} announce to ${channel}, @channel standy times!`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}.`; + } +} diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index b65956975..86fbe6bee 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -16,6 +16,7 @@ Prototype Refactor * destroy() // prototype method that returns: `${this.name} was removed from the game.` * */ + class GameObject { constructor(attribute) { this.createdAt = attribute.createdAt; @@ -27,12 +28,14 @@ class GameObject { return `${this.name} was removed from the game.`; } } + /* === CharacterStats === * healthPoints * takeDamage() // prototype method -> returns the string ' took damage.' * should inherit destroy() from GameObject's prototype */ + class CharacterStats extends GameObject { constructor(stats) { super(stats); @@ -65,24 +68,6 @@ class Humanoid extends CharacterStats { } } -// function Humanoid(profile) { -// CharacterStats.call(this, profile); -// this.team = profile.team; -// this.weapons = profile.weapons; -// this.language = profile.language; - -// // *** Again abstracting with a prototype below***// -// // this.greet = function() { -// // return `${this.newName} offers a greeting in ${this.newLanguage}.`; -// // }; -// } - -// //Object.create() allows the constructor function to see/inherit a parent function -// Humanoid.prototype = Object.create(CharacterStats.prototype); - -// Humanoid.prototype.greet = function() { -// return `${this.newName} offers a greeting in ${this.newLanguage}.`; -// }; /* * Inheritance chain: GameObject -> CharacterStats -> Humanoid * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. From b96d0914a0642a5b8ffe508b12edbe53a0725818 Mon Sep 17 00:00:00 2001 From: Greg Hayes Date: Fri, 20 Sep 2019 00:40:00 -0500 Subject: [PATCH 3/4] Added student/instructor/PM objects --- assignments/lambda-classes.js | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 5ce5653f6..c6d677e62 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -13,6 +13,7 @@ class Person { class Instructor extends Person { constructor(attribute) { + super(attribute); this.specialty = attribute.specialty; this.favLanguage = attribute.favLanguage; this.catchPhrase = attribute.catchPhrase; @@ -27,6 +28,7 @@ class Instructor extends Person { class Student extends Person { constructor(attribute) { + super(attribute); this.previousBackground = attribute.previousBackground; this.className = attribute.className; this.favSubjects = attribute.favSubjects; @@ -37,10 +39,14 @@ class Student extends Person { PRAssignment(subject) { return `${this.name} has submitted a PR Assignment for ${subject}.`; } + sprintChallenge(subject) { + return `${this.name} has begun the sprint challenge on ${subject}!`; + } } class ProjectManager extends Instructor { constructor(attribute) { + super(attribute); this.gradClassName = attribute.gradClassName; this.favInstructor = attribute.favIntructor; } @@ -51,3 +57,72 @@ class ProjectManager extends Instructor { return `${this.name} debugs ${student.name}'s code on ${subject}.`; } } + +const student_one = new Student({ + name: "Greg", + age: 30, + location: "Austin", + previousBackground: "Uber", + className: "Javascript II", + favSubjects: ["HTML", "Javascript", "CS"] +}); + +const student_two = new Student({ + name: "Colin", + age: 28, + location: "Salt Lake City", + previousBackground: "Sales", + className: "Javascript II", + favSubjects: ["HTML", "Javascript", "CS"] +}); + +const student_three = new Student({ + name: "Eric", + age: 22, + location: "San Antonio", + previousBackground: "Retail", + className: "Javascript II", + favSubjects: ["HTML", "Javascript", "CS"] +}); + +const instructor_one = new Instructor({ + name: "Brit Demming", + age: 31, + location: "Canada", + specialty: "Keepin' it real", + favLanguage: "Javascript, HTML, CSS", + catchPhrase: "You're gonna know all about my pets" +}); + +const instructor_two = new Instructor({ + name: "Ryan Hamblin", + age: 32, + location: "Salt Lake City", + specialty: "Prototypical Inheritance", + favLanguage: "Javascript, React", + catchPhrase: "Put the keys in the car" +}); + +const projectManager_one = new ProjectManager({ + name: "Don Whitely", + age: 40, + location: "Indianapolis", + specialty: "Troubleshooting", + favLanguage: "React, Python", + catchPhrase: "Hold em' or Fold em'", + gradClassName: "Web13", + favInstructor: "James Starks" +}); + +const projectManager_two = new ProjectManager({ + name: "Joseph Hayden", + age: 30, + location: "Chicago", + specialty: "Keepin' it real", + favLanguage: "Javascript, Python", + catchPhrase: "Wubba Lubba Javascript", + gradClassName: "Web18", + favInstructor: "Brit Demming" +}); + +console.log(student_three.PRAssignment("CSS")); From 91c49827ebfb77a893faff762c4ad253a68f7897 Mon Sep 17 00:00:00 2001 From: Greg Hayes Date: Fri, 20 Sep 2019 00:48:28 -0500 Subject: [PATCH 4/4] Behaving as expected, testing additional methods --- assignments/lambda-classes.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index c6d677e62..6276370db 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -19,7 +19,7 @@ class Instructor extends Person { this.catchPhrase = attribute.catchPhrase; } demo(subject) { - return `Today we are learning about ${this.subject}.`; + return `Today we are learning about ${subject}.`; } grade(student, subject) { return `${student.name} receives a perfect score on ${this.subject}!`; @@ -51,10 +51,10 @@ class ProjectManager extends Instructor { this.favInstructor = attribute.favIntructor; } standUp(channel) { - return `${this.name} announce to ${channel}, @channel standy times!`; + return `${this.name} announces to ${channel}, @channel standy times!`; } debugsCode(student, subject) { - return `${this.name} debugs ${student.name}'s code on ${subject}.`; + return `${this.name} debugs ${student}'s code on ${subject}.`; } } @@ -73,7 +73,7 @@ const student_two = new Student({ location: "Salt Lake City", previousBackground: "Sales", className: "Javascript II", - favSubjects: ["HTML", "Javascript", "CS"] + favSubjects: ["Javascript", "Redux"] }); const student_three = new Student({ @@ -82,7 +82,7 @@ const student_three = new Student({ location: "San Antonio", previousBackground: "Retail", className: "Javascript II", - favSubjects: ["HTML", "Javascript", "CS"] + favSubjects: ["HTML", "CSS", "npm"] }); const instructor_one = new Instructor({ @@ -126,3 +126,6 @@ const projectManager_two = new ProjectManager({ }); console.log(student_three.PRAssignment("CSS")); +console.log(projectManager_one.standUp("Web24")); +console.log(projectManager_two.debugsCode("Greg", "CSS")); +console.log(instructor_two.demo("callback functions"));