From a8feb753811e4116581b8bae9ee3af669008495f Mon Sep 17 00:00:00 2001 From: josh Hill Date: Thu, 17 Oct 2019 13:11:20 -0400 Subject: [PATCH 1/2] prototype-refactor --- assignments/prototype-refactor.js | 162 ++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..c7e3e7470 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,165 @@ 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 GameObject { + constructor(attributes){ + this.createdAt = attributes.createdAt; + this.name = attributes.name; + this.dimensions = attributes.dimensions; + + } + destroy(){ + return `${this.name} was removed from the game.`; + } +} + +class CharacterStats extends GameObject{ + constructor(attributes){ + super(attributes); + this.healthPoints = attributes.healthPoints; + } + takeDamage(){ + return `${this.name} took damage.`; + } +} + +class Humanoid extends CharacterStats{ + constructor(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}`; + } +} + +// function GameObject(attributes){ +// this.createdAt = attributes.createdAt; +// this.name = attributes.name; +// this.dimensions = attributes.dimensions; + +// } +// GameObject.prototype.destroy = function(){ +// return `${this.name} was removed from the game.`; +// } + + +// function CharacterStats(attributes){ +// this.healthPoints = attributes.healthPoints; +// GameObject.call(this, attributes); +// } +// CharacterStats.prototype = Object.create(GameObject.prototype) + +// CharacterStats.prototype.takeDamage = function (){ +// return `${this.name} took damage.`; +// } + + +// function Humanoid(attributes){ +// this.team = attributes.team; +// this.weapons = attributes.weapons; +// this.language = attributes.language; +// CharacterStats.call(this, attributes); +// } +// Humanoid.prototype = Object.create(CharacterStats.prototype); +// Humanoid.prototype.greet = function(){ +// return `${this.name} offers a greeting in ${this.language}`; +// } +/* + === 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.` +*/ + +/* + === CharacterStats === + * healthPoints + * takeDamage() // prototype method -> returns the string ' took damage.' + * should inherit destroy() from GameObject's prototype +*/ + +/* + === 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 +*/ + +/* + * 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[0]); // 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 3003b1d7a19fb8d829aaff4256321c164adf367a Mon Sep 17 00:00:00 2001 From: josh Hill Date: Thu, 17 Oct 2019 15:04:08 -0400 Subject: [PATCH 2/2] MVP --- assignments/lambda-classes.js | 169 ++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 37 +------ 2 files changed, 170 insertions(+), 36 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..d47cba7ca 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,170 @@ // CODE here for your Lambda Classes +class Person{ + constructor(atts){ + this.name = atts.name; + this.age = atts.name; + this.location = atts.location; + this.subject = atts.subject; + } + speak(){ + return `Hello my name is ${this.name}, I am from the ${this.location}!` + } +} + +class Student extends Person{ + constructor(atts){ + super(atts); + this.previousBackground = atts.previousBackground; + this.className = atts.className; + this.favSubjects = atts.favSubjects; + } + listsSubjects(){ + return `These are my favorite subjects - ${this.favSubjects}!` + } + prAssignment(){ + return `${this.name} has submitted a PR for ${this.subject}!` + } + sprintChallenge(){ + return `${this.name} has begun sprint challenge on ${this.subject}!` + } +} + +class Instructor extends Person{ + constructor(atts){ + super(atts); + this.specialty = atts.specialty; + this.favLanguage = atts.favLanguage; + this.catchPhrase = atts.catchPhrase; + + } + demo(){ + return `Today we are learning about ${this.subject}!` + } + grade(){ + return `${Student.name} receives a perfect score on ${this.subject}!` + } +} + +class ProjectManager extends Instructor{ + constructor(atts){ + super(atts); + this.gradClassName = atts.gradClassName; + this.favInstructor = atts.favInstructor; + this.channel = atts.channel; + } + standUp(){ + return `${this.name} announces to ${this.channel}, @channel standy times!` + } + debugsCode(){ + return `${this.name} debugs ${Student.name}'s code on ${this.subject}!` + } +} + + +const james = new Person({ + name: "James", + age: 33, + location: "USA", + subject: "biology" + +}) + +console.log(james.speak()); + +const emily = new Person({ + name: "Emily", + age: 33, + location: "Austrailia", + subject: "biology" + +}) + +// console.log(emily.speak()); + +const brit = new Instructor({ + name: "Brit", + age: 25, + location: "USA", + subject: "Classes", + specialty: "Web Development", + favLanguage: "JS", + catchPhrase: "AYEEE IM CANADIAN!" + +}) + +console.log(brit.demo()); +console.log(brit.grade()); + +const jordan = new Instructor({ + name: "Jordan", + age: 25, + location: "USA", + subject: "Classes", + specialty: "Web Development", + favLanguage: "JS", + catchPhrase: "AYEEE IM CANADIAN!" + +}) + +// console.log(jordan.demo()); +// console.log(jordan.grade()); + +const josh = new Student({ + name: "Josh", + age: 22, + location: "USA", + subject: "Classes", + previousBackground: "College Student", + className: "WEB25", + favSubjects: "JavaScript, HTML, CSS" +}) +console.log(josh.listsSubjects()); +console.log(josh.prAssignment()); +console.log(josh.sprintChallenge()); + +const brendan = new Student({ + name: "Brendan", + age: 22, + location: "USA", + subject: "Classes", + previousBackground: "College Student", + className: "WEB25", + favSubjects: "JavaScript, HTML, CSS" +}) + +// console.log(brendan.listsSubjects()) +// console.log(brendan.prAssignment()) +// console.log(brendan.sprintChallenge()) + +const roenz = new ProjectManager({ + name: "Roenz", + age: 26, + location: "USA", + subject: "Classes", + specialty: "Web Development", + favLanguage: "JS", + catchPhrase: "MACHINE LEARNING!", + gradClassName: "WEB20??", + favInstructor: "BRITTTTTT", + channel: "the slack channel WEB_25_ROENZ" +}) + +console.log(roenz.standUp()); +console.log(roenz.debugsCode()); + + +const ryan = new ProjectManager({ + name: "Ryan", + age: 26, + location: "USA", + subject: "Classes", + specialty: "Web Development", + favLanguage: "JS", + catchPhrase: "MACHINE LEARNING!", + gradClassName: "WEB20??", + favInstructor: "BRITTTTTT", + channel: "the slack channel WEB_25_RYAN" +}) + +// console.log(ryan.standUp()); +// console.log(ryan.debugsCode()); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index c7e3e7470..2f1b0b225 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -71,42 +71,7 @@ class Humanoid extends CharacterStats{ // this.language = attributes.language; // CharacterStats.call(this, attributes); // } -// Humanoid.prototype = Object.create(CharacterStats.prototype); -// Humanoid.prototype.greet = function(){ -// return `${this.name} offers a greeting in ${this.language}`; -// } -/* - === 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.` -*/ - -/* - === CharacterStats === - * healthPoints - * takeDamage() // prototype method -> returns the string ' took damage.' - * should inherit destroy() from GameObject's prototype -*/ - -/* - === 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 -*/ - -/* - * 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({