diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..74bd687b6 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,124 @@ // CODE here for your Lambda Classes +class Person { + constructor(attrs) { + this.name = attrs.name; + this.location = attrs.location; + this.age = attrs.age; + } + speak() { + return `Hello my name is ${this.name}, and I am from ${this.location}.` + } +} + +class Instructor extends Person { + constructor(attrs) { + super(attrs); + this.specialty = attrs.specialty; + this.favLanguage = attrs.favLanguage; + this.catchPhrase = attrs.catchPhrase; + } + demo(subject) { + return `Today we are learning about ${subject}`; + } + grade(student, subject) { + return `${student} receives a perfect score on ${subject}`; + } +} + +class Student extends Person { + constructor(attrs){ + super(attrs) + this.previousBackground = attrs.previousBackground; + this.className = attrs.className; + this.favSubjects = attrs.favSubjects; + } + listsSubjects() { + return `${this.favSubjects[favSubjects.length]}`; + } + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}`; + } + sprintChallenge(subject) { + return `${this.name} has begun sprint challenge on ${subject}`; + } +} + +class TeamLead extends Instructor { + constructor(attrs) { + super(attrs); + this.gradClassName = attrs.gradClassName; + this.favInstructor = attrs.favInstructor; + } + standUp(slackChannel) { + return `${this.name} announces to ${slackChannel}, @channel standy times!`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student}'s code on ${subject}` + } +} + +// class Person { +// constructor(attrs) { +// this.name = attrs.name; +// this.location = attrs.location; +// this.age = attrs.age; +// } + +const instructor_one = new Instructor({ + name: 'Charles', + location: 'Wisconsin', + age: 35, + specialty: 'Javascript', + favLanguage: 'Javascript', + catchPhrase: 'Remember the classes!' +}) + +const student_one = new Student({ + name: 'Brenda', + location: 'Florida', + age: 22, + previousBackground: 'Retail', + className: 'WEBPT11', + favSubjects: ['Math', 'Graphic Design', 'HTML', 'CSS'], +}) + +const student_two = new Student({ + name: 'Linda', + location: 'Colorado', + age: 24, + previousBackground: 'Customer Service Representative', + className: 'WEB22', + favSubjects: ['Creative Writing', 'Drawing101', 'Javascript', 'Music Theory'] +}) + +const student_three = new Student({ + name: 'Bob', + location: 'Kentucky', + age: 50, + previousBackground: 'Cashier', + className: 'WEBPT8', + favSubjects: ['Calculus', 'Science', 'Python', 'Drama'] +}) + +const team_lead = new TeamLead({ + name: 'Leo', + location: 'California', + age: 27, + specialty: 'Javascript', + favLanguage: 'Javascript', + catchPhrase: 'Don\'t throw me under the bus!', + gradClassName: 'WEB22', + favInstructor: 'Pace' +}) + +console.log(student_one.name); +console.log(instructor_one.favLanguage); +console.log(instructor_one.demo('Math')); +console.log(instructor_one.grade(student_two.name, 'Drama')); +console.log(team_lead.name); +console.log(team_lead.catchPhrase); +console.log(student_three.favSubjects); +console.log(team_lead.debugsCode(student_three.name, student_three.favSubjects[1])); +console.log(team_lead.standUp('webpt11')); +console.log(team_lead.speak()); +console.log(instructor_one.speak()); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..41d1d8805 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,175 @@ 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. */ +/* + Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy. + + In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. + + At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions. + + Each constructor function has unique properties and methods that are defined in their block comments below: +*/ + +/* + === 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.` +*/ +// function GameObject(attrs){ +// this.createdAt = attrs.createdAt; +// this.name = attrs.name; +// this.dimensions = attrs.dimensions +// } + +// GameObject.prototype.destroy = function(){ +// return `${this.name} was removed from the game.`; +// } + class GameObject { + constructor(attrs) { + this.createdAt = attrs.createdAt; + this.name = attrs.name; + this.dimensions = attrs.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(attrs) { +// GameObject.call(this, attrs); +// this.healthPoints = attrs.healthPoints; +// } +// CharacterStats.prototype = Object.create(GameObject.prototype); + +// CharacterStats.prototype.takeDamage = function() { +// return `${this.name} took damage.`; +// } + + class CharacterStats extends GameObject { + constructor(attrs) { + super(attrs); + this.healthPoints = attrs.healthPoints; + } + + takeDamage() { + 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(attrs) { +// CharacterStats.call(this, attrs); +// this.team = attrs.team; +// this.weapons = attrs.weapons; +// this.language = attrs.language +// } +// Humanoid.prototype = Object.create(CharacterStats.prototype); + +// Humanoid.prototype.greet = function() { +// return `${this.name} offers a greeting in ${this.language}`; +// } + + class Humanoid extends CharacterStats{ + constructor(attrs) { + super(attrs); + this.team = attrs.team; + this.weapons = attrs.weapons; + this.language = attrs.language; + } + greet() { + 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. + + + // Stretch task: + // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. + // * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0; + // * Create two new objects, one a villain and one a hero and fight it out with methods! \ No newline at end of file