diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..e6b0fcf9e 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,82 @@ // CODE here for your Lambda Classes + +class Person{ + constructor(attributes){ + this.newName = attributes.newName + this.newAge = attributes.newAge + this.newLocation = attributes.newLocation + } + speak(){ + return `Hello my name is ${this.newName}, I am from ${this.newLocation}` + } +} + +class Instructor extends Person{ + constructor(instructorAttributes){ + super(instructorAttributes); + this.newSpecialty = instructorAttributes.specialty + this.newFavLanguage = instructorAttributes.favLanguage + this.newCatchPhrase = instructorAttributes.catchPhrase + } + demo(subject){ + return `Today we are learning about ${subject}` //Need to add a subject string as an argument + } + grade(student, subject){ + return `${student.name} receives a perfect score on {subject}` //Need to add student as an object and a subject string as arguments + } +} + +class Student extends Person{ + constructor(studentAttributes){ + super(studentAttributes); + this.previousBackground = studentAttributes.previousBackground + this.className = studentAttributes.className + this.favSubjects = studentAttributes.favSubjects + } + listsSubjects(){ //need a method that logs out all of the student's favoriteSubjects one by one + + } + PRAssignment(){ //need a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject} + return `${student.name} has submitted a PR for ${subject}` + } + sprintChallenge(){ + return `${student.name} has begun sprint challenge on ${subject}` + } +} + +class ProjectManagers extends Instructor{ + constructor(ProjectManagersAttritubes){ + super(ProjectManagersAttritubes); + this.gradClassName = ProjectManagersAttritubes.gradClassName + this.favInstructor = ProjectManagersAttritubes.favInstructor + } + standUp(){ + return `${name} announces to ${channel}, @channel standy times!` + } + debugsCode(student){ + return `${name} debugs ${student.name}'s code on ${subject}` + } +} + +const Steve = new Person({ + name: 'Steve', + age: 41, + location: 'Seattle', +}) + +const Brit = new Instructor({ + specialty: 'teaching', + favLanguage: 'JavaScript', + catchPhrase: 'Ehhhh', +}) + +const Skippy = new Student({ + previousBackground: 'McDonalds', + className: 'Web23', + favSubjects: 'HTML', +}) + +const Tyler = new ProjectManagers({ + gradClassName: 'Web1', + favInstructor: 'Shanaynay', +}) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..4e6147657 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,155 @@ 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. */ +// 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.`; +// } + +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.`; + } +} + + /* + === CharacterStats === + * healthPoints + * takeDamage() // prototype method -> returns the string ' took damage.' + * should inherit destroy() from GameObject's prototype + */ + +// function CharacterStats(attributes2) { +// GameObject.call(this, attributes2); +// this.healthPoints = attributes2.healthPoints; +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); +class CharacterStats{ + constructor(attributes2) { + GameObject.call(this, attributes2); + this.healthPoints = attributes2.healthPoints; + } + // CharacterStats.prototype = Object.create(GameObject.prototype); + takeDamage() { + return `${this.name} took damage`; + } +} + +// CharacterStats.prototype.takeDamage = function() { +// 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 + */ + +// function Humanoid(attributes3) { +// CharacterStats.call(this, attributes3); +// this.team = attributes3.team; +// this.weapons = attributes3.weapons; +// this.language = attributes3.language; +// } + +class Humanoid{ + constructor(attributes3) { + this.team = attributes3.team; + this.weapons = attributes3.weapons; + this.language = attributes3.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}`; +// }; + /* + * 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. + \ No newline at end of file