From 7889b76a6498ff14f2e2254d66742d2980af4d4e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 May 2018 18:25:31 -0400 Subject: [PATCH] Finished working with classes --- assignments/lambda-classes.js | 80 +++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 38 +++++++-------- 2 files changed, 99 insertions(+), 19 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..e0757f688 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,81 @@ // CODE here for your Lambda Classes +class Person { + constructor(info) { + this.name= info.name; + this.age= info.age; + this.location= info.location; + this.gender= info.gender; + } + speak(){ + console.log(`Hello my name is ${this.name}, I am from ${this.location}.`); + } +} + +class Instructor extends Person { + constructor(instructorInfo){ + super(instructorInfo); + this.speacialty= instructorInfo.speacialty; + this.favLanguage= instructorInfo.favLanguage; + this.catchPhrase= instructorInfo.catchPhrase; + } + demo(subject){ + console.log(`Today we are learning about ${subject}.`); + } + grade(student,subject){ + console.log(`${student.name} receives a perfect score on ${subject}.`); + } +} + +class Student extends Person { + constructor(studentInfo){ + super(studentInfo); + this.previousBackground =studentInfo.previousBackground; + this.className= studentInfo.className; + this.favSubjects= studentInfo.favSubjects; + } + listsSubjects(){ + console.log(`${this.favSubjects}`); + } + 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 Pms extends Instructor{ + constructor(pmInfo){ + super(pmInfo); + this.gradClassName= pmInfo.gradClassName; + this.favInstructor= pmInfo.favInstructor; + } + standUp(channel){ + console.log(`${this.name} announces to ${channel}, @channel standup times!`); + } + debugsCode(student,subject){ + console.log(`${this.name} debugs ${student.name}'s code on ${subject}.`); + +} +} + + +const Josh= new Instructor({ + name:'Josh', + gender:'male', + favLanguage:'JavaScript', + catchPhrase: `Don't forget the homies.` +}); + +const Justin= new Pms({ + name:'Justin', + gender:'male', + favInstructor:'Josh' +}); + +const Alex= new Student ({ + name: 'Alex', + gender:'male', + age: 25, + className:'cs11' +}); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..90ae99245 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() { +destroy(){ return `Object was removed from the game.`; -}; +} +} -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); + +class CharacterStats extends GameObject { + constructor(characterStatsOptions){ + super(characterStatsOptions); this.hp = characterStatsOptions.hp; this.name = characterStatsOptions.name; } - -CharacterStats.prototype = Object.create(GameObject.prototype); - -CharacterStats.prototype.takeDamage = function() { +takeDamage(){ return `${this.name} took damage.`; -}; +} +} -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); +class Humanoid extends CharacterStats { + constructor(humanoidOptions){ + super(humanoidOptions); this.faction = humanoidOptions.faction; this.weapons = humanoidOptions.weapons; this.language = humanoidOptions.language; } - -Humanoid.prototype = Object.create(CharacterStats.prototype); - -Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; -}; +greet(){ + return `${this.name} offers a greeting in ${this.language}`; +} +} const mage = new Humanoid({ createdAt: new Date(),