From c3d46586da2a907039bf386ba850f812ce8916c6 Mon Sep 17 00:00:00 2001 From: drkfogle Date: Thu, 29 Nov 2018 15:38:10 -0500 Subject: [PATCH 1/3] prototype.js Successfully refactored --- assignments/prototype-refactor.js | 119 ++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..95cea3894 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -3,7 +3,126 @@ Prototype Refactor 1. Copy and paste your code or the solution from yesterday +function GameObject(attributes){ + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; + this.name = attributes.name; + GameObject.prototype.destroy = function(){ + return `${this.name} was removed from the game.` + } +} + +function CharacterStats(attributes){ + GameObject.call(this, attributes); + this.healthPoints = attributes.healthPoints; + this.name = attributes.name; +} +CharacterStats.prototype = Object.create(GameObject.prototype) + + CharacterStats.prototype.takeDamage = function(){ + return (`${this.name} took damage.`) + } + + function Humanoid(attributes){ + CharacterStats.call(this,attributes); + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + Humanoid.prototype = Object.create(CharacterStats.prototype); + + Humanoid.prototype.greet = function(){ + return (`${this.name} offers a greeting in ${this.language}`) + } + + + 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.dimensions = attributes.dimensions; + this.name = attributes.name; + } + destroy(){ + return `${this.name} was removed from the game.` + } +} + +class CharacterStats extends GameObject{ + constructor (attributes){ + super(attributes); + this.healthPoints = attributes.healthPoints; + this.name = attributes.name; + } + 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}`) + } +} + +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', + }); From 4c8e3e85e4b68c7cee53099687a46d79a454d066 Mon Sep 17 00:00:00 2001 From: drkfogle Date: Thu, 29 Nov 2018 18:24:12 -0500 Subject: [PATCH 2/3] Lambda Classes Updated, Currently Testing --- assignments/lambda-classes.js | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..92d381d49 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,59 @@ // 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 Instructors extends Person{ + constructor (attributes){ + super(attributes); + this.specialty = attributes.specialty; + this.favLanguage = attributes.favLanguage; + this.catchPhrase = attributes.catchPhrase; + } + demo(Subject){ + console.log(`Today we are learning about ${subject}.`) + } + grade(Subject){ + console.log(`${this.name} receives a perfect score on ${subject}`) + } +} + +class Student extends Person{ + constructor (attributes){ + super(attributes); + this.previousBackground = attributes.previousBackground; + this.className = attributes.className; + this.favSubject = attributes.favSubject; + } + listsSubjects(){ + console.log(this.favSubject) + } + PRAssignment(subject){ + console.log(`${student.name} has submitted a PR for ${subject}.`) + } + sprintChallenge(subject){ + console.log(`${student.name} has begun sprint challenge on ${subject}.`) + } +} + +class PM extends Instructors{ + constructor (attributes){ + super(attributes); + this.gradClassName = attributes.gradClassName; + this.favInstructor = attributes.favInstructor; + } + standUp(name){ + console.log(`${name} announces to channel, @Channel stand times!`) + } + debugsCode(name,subject){ + console.log(`${name}debugs ${student.name}'s code on ${subject}`) + } +} \ No newline at end of file From 4bc575c67be90558e5fe593e301a891aee8695e8 Mon Sep 17 00:00:00 2001 From: drkfogle Date: Thu, 29 Nov 2018 18:30:06 -0500 Subject: [PATCH 3/3] Tested Code --- assignments/lambda-classes.js | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 92d381d49..e67eccacb 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1,16 +1,3 @@ -// 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 Instructors extends Person{ constructor (attributes){ super(attributes); @@ -18,10 +5,10 @@ class Instructors extends Person{ this.favLanguage = attributes.favLanguage; this.catchPhrase = attributes.catchPhrase; } - demo(Subject){ + demo(subject){ console.log(`Today we are learning about ${subject}.`) } - grade(Subject){ + grade(subject){ console.log(`${this.name} receives a perfect score on ${subject}`) } } @@ -37,10 +24,10 @@ class Student extends Person{ console.log(this.favSubject) } PRAssignment(subject){ - console.log(`${student.name} has submitted a PR for ${subject}.`) + console.log(`${Student.name} has submitted a PR for ${subject}.`) } sprintChallenge(subject){ - console.log(`${student.name} has begun sprint challenge on ${subject}.`) + console.log(`${Student.name} has begun sprint challenge on ${subject}.`) } } @@ -53,7 +40,7 @@ class PM extends Instructors{ standUp(name){ console.log(`${name} announces to channel, @Channel stand times!`) } - debugsCode(name,subject){ - console.log(`${name}debugs ${student.name}'s code on ${subject}`) + debugsCode(name,studentName,subject){ + console.log(`${name}debugs ${studentName}'s code on ${subject}`) } } \ No newline at end of file