diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..f925cfb23 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,144 @@ -// CODE here for your Lambda Classes +//Classes: + +class Person{ + constructor(attributes){ + this.name = attributes.name, + this.age = attributes.age, + this.location = attributes.location + } + speak(){ + return `Hello, my name is ${this.name}, I am from ${this.location}.`; + } +} + + + +class Instructor extends Person{ + constructor(InstructorAttributes){ + super(InstructorAttributes); + this.specialty = InstructorAttributes.specialty, + this.favLanguage = InstructorAttributes.favLanguage, + this.catchPhrase = InstructorAttributes.catchPhrase + } + demo(subject){ + return `Today we are learning about ${subject}.` + } + grade(student, subject){ + return `${student.name} receives a perfect score on ${subject}!`; + } + +} + + + +class Student extends Instructor{ + constructor(StudentAttributes){ + super(StudentAttributes); + this.previousBackground = StudentAttributes.previousBackground, + this.className = StudentAttributes.className, + this.favSubjects = StudentAttributes.favSubjects + } + listsSubjects(){ + return `${this.favSubjects}` + } + PRAssignment(student, subject){ + return `${student.name} has submitted a PR for ${subject}`; + } +} + + + +class ProjectManager extends Student{ + constructor(ProjectManagerAttributes){ + super(ProjectManagerAttributes); + this.gradClassName = ProjectManagerAttributes.gradClassName, + this.favInstructor = ProjectManagerAttributes.favInstructor + } + standUp(channel){ + return `${this.name} announces to ${channel}, @channel stand times!​​​​​`; + } + debugsCode(student, subject ){ + return `${this.name} debugs ${student.name}'s code on ${subject}`; + } + +} + +//______________________________________________________________________ +//instructors: + +const Jerry = new Instructor({ + name: 'Jerry', + location: 'Utah', + age: 42, + favLanguage: 'Java', + specialty: 'Computer Science Theory', + catchPhrase: `Love the whales` + }); + +const Aya = new Instructor({ + name: 'Aya', + location: 'Wisconsin', + age: 48, + favLanguage: 'C++', + specialty: 'DevOps', + catchPhrase: `I like cats` + }); + +//______________________________________________________________________ +//students: + + +const Jon = new Student({ + name: 'Jon', + location: 'Idaho', + age: 36, + previousBackground: `cook`, + className: `CS122`, + favSubjects: `front-end` + }); + +const Jeremy = new Student({ + name: 'Jeremy', + location: 'UK', + age: 22, + previousBackground: `college student`, + className: `CS125`, + favSubjects: `back-end` + }); + +//______________________________________________________________________ +//projectManagers: + +const Kate = new ProjectManager({ + name: 'Kate', + location: 'New Zealand', + age: 53, + gradClassName: 'Web1', + favInstructor: 'Aya' + }); + +const Kerin = new ProjectManager({ + name: 'Kerin', + location: 'Japan', + age: 37, + gradClassName: 'IOS12', + favInstructor: 'Jerry' + }); + + +//______________________________________________________________________ +//console.logs for instructors: + +console.log(Jerry.speak()); +console.log(Jerry.demo('math')); +console.log(Aya.speak()); +console.log(Aya.demo('science')); +console.log(Jerry.grade(Jon, 'Computer Science')) +//______________________________________________________________________ +//console.logs for students: + +console.log(Jon.) + + +//______________________________________________________________________ +//console.logs for projectManagers: \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..cb9d12c56 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -6,4 +6,137 @@ 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. +/* +=== 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.` */ + +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 +*/ +class CharacterStats extends GameObject{ + constructor(childAttributes){ + super(childAttributes); + this.healthPoints = childAttributes.healthPoints + } + takeDamage(_destroy) { + 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 +*/ + +class Humanoid extends CharacterStats { + constructor(grandChildAttributes) { + super(grandChildAttributes); + this.team = grandChildAttributes.team, + this.weapons = grandChildAttributes.weapons, + this.language = grandChildAttributes.language + } + greet(_destroy, _takeDamage) { + 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. +