diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..c8fd88a0a 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,130 @@ // CODE here for your Lambda Classes +class Person{ + constructor(personInfo){ + this.name=personInfo.name; + this.age=personInfo.age; + this.location=personInfo.location; + this.gender=personInfo.gender; + } + speak(){ + console.log(`Hello my name is ${this.name} and I'm from ${this.location}`); + } +} + +const bob={ +name:'bob', +age:"24", +location:"cincinnati", +gender:"m", +} + +let bobAnswer=new Person(bob); +bobAnswer.speak(); + +class Instructor extends Person{ + constructor(instructorInfo){ + super(instructorInfo); + this.specialty=instructorInfo.specialty; + 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} gets a perfect grade in a${subject}`); + } + changeGrade(student){ + student.grade=student.grade +Math.floor((Math.random()*10)); + } +} + +const instructorOne={ + name:'roger', + age:"37", + location:"France", + gender:"m", + specialty:"redux", + favLanguage:"javascript", + catchPhrase:"yabba dabba doo", +} + +const instructorOneAnswer=new Instructor(instructorOne); +console.log(instructorOneAnswer); +instructorOneAnswer.demo("math"); + + +class Student extends Person{ + constructor(studentInfo){ + super(studentInfo); + this.previousBackground=studentInfo.previousBackground; + this.className=studentInfo.className; + this.favSubjects=studentInfo.favSubjects; + this.grade=studentInfo.grade; + } + listsSubjects(){ + this.favSubjects.forEach(function (item){ + console.log(item); + }); + } + PRAssignment(subject){ + console.log(`${this.name} submitted a PR request for subject ${subject}`) + } + sprintChallenge(subject){ + console.log(`${this.name} has begun a sprint challenge for ${subject}`) + } + graduate(){ + if(this.grade<70) {console.log(`Your grade is ${this.grade} better do some more work!`) + + }else{console.log("congrats you passed!")}} + + }; + + const susan={ + name:'susan', + age:"63", + location:"New York City", + gender:"f", + previousBackground:"soccer coach", + className:"CSPT3", + favSubjects:["lunch","recess","spelling"], + grade:1, + } + + const susanAnswer=new Student(susan); + console.log(susanAnswer); + susanAnswer.listsSubjects(); + susanAnswer.PRAssignment("math"); + susanAnswer.sprintChallenge("math"); + + instructorOneAnswer.grade(susanAnswer, "math"); + +class ProjectManager extends Instructor{ + constructor(pmInfo){ + super(pmInfo); + this.gradClassName=pmInfo.gradClassName; + this.favInstructor=pmInfo.favInstructor; + } + standUp(channel){ + console.log(`${this.name} announces to ${channel} the standup times`); + } + debugsCode(student,subject){ + console.log(`${this.name} debugs ${student.name}'s project on ${subject}`) + + } +} + +const captainAmerica={ + name:'Steve Rogers', + age:"100", + location:"unknown", + gender:"m", + specialty:"shield", + favLanguage:"fists", + catchPhrase:"do the right thing", + gradClassName:"CS1", + favInstructor:"Dan Frehner" +} +const captainAmericaAnswer=new ProjectManager(captainAmerica); +captainAmericaAnswer.standUp("#random"); +captainAmericaAnswer.debugsCode(susanAnswer,"math"); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..767336c39 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,40 +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) { - this.createdAt = options.createdAt; - this.dimensions = options.dimensions; -} - -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; -}; +class GameObject{ + constructor(options){ + this.createdAt = options.createdAt; + this.dimensions = options.dimensions; + } + destroy(){ + return `${this.name} was removed from the game.`; + } + }; -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); - this.hp = characterStatsOptions.hp; - this.name = characterStatsOptions.name; +class CharacterStats extends GameObject{ + constructor(characterStatsOptions){ + super(characterStatsOptions); + this.hp = characterStatsOptions.hp; + this.name = characterStatsOptions.name; + } + takeDamage(){ + return `${this.name} took damage.`; + } } - -CharacterStats.prototype = Object.create(GameObject.prototype); - -CharacterStats.prototype.takeDamage = function() { - 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; + } + greet(){ + return `${this.name} offers a greeting in ${this.language}.`; + } } -Humanoid.prototype = Object.create(CharacterStats.prototype); - -Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; -}; - const mage = new Humanoid({ createdAt: new Date(), dimensions: {