diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..abd957099 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,199 @@ // CODE here for your Lambda 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(attributes){ + super(attributes); + this.specialty = attributes.specialty; + this.favLanguage = attributes.favLanguage; + this.catchPhrase = attributes.catchPhrase +} + demo(){ + return `Today we are learning about ${this.specialty}`; + }; + grade(){ + return `${this.name} receives a perfect score on ${this.specialty}`; + }; + add(){ + return `Let's give ${this.name} 10 extra points for effort!`; + }; + + sub(){ + return ` ${this.name} will suffer 10 extra points off for not finishing the project!`; + }; +} + +class Student extends Person{ + constructor(attributes){ + super(attributes); + this.previousBackground = attributes.previousBackground; + this.className = attributes.className; + this.favSubjects = attributes.favSubjects +} + functionlistSubjects(){ + this.favSubjects.forEach(element => {console.log(element)}) +} + + PRAssignment(){ + return `${this.name} has submitted a PR for ${this.className}`; +}; + + sprintChallenge(){ + return ` ${this.name} has begun sprint challenge on ${this.className}`; +}; +} + + +class ProjectManager extends Instructor{ + constructor(attributes){ + super(attributes); + this.gradClassName = attributes.gradClassName; + this.favInstructor = attributes.favInstructor +} + standUp(){ + return `${this.name} announces ${this.gradClassName}, @channel standy times!`; + }; + + debugsCode(){ + return `${this.name} debugs ${student.name}'s code on ${this.subject}`; + }; + +} + + +const Tom = new Person({ + name: 'Tom', + age: 47, + location: 'Bed' + }); + + + +const Freddy = new Person({ + name: 'Fredddy', + age: 27, + location: 'Rock' + }); + + +const Tim = new Person({ + name: 'Tim', + age: 28, + location: 'Rock-bed' + }); + + + +const F = new Instructor({ + name: 'F', + location: 'Cali', + age: 27, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the food` + }); + + const T = new Instructor({ + name: 'T', + location: 'Montana', + age: 24, + favLanguage: 'JAVA', + specialty: 'Servers', + catchPhrase: `let me SERVER you` + }); + + + const M = new Instructor({ + name: 'M', + location: 'Boston', + age: 30, + favLanguage: 'Python', + specialty: 'Back-end', + catchPhrase: `I don't bite` + }); + + + const Ted = new Student({ + name: 'Ted', + age: 22, + location: 'Denver', + previousBackground: 'chef', + className: 'Java', + favSubjects: ['math', 'science', 'biology', 'arts'], + grade: 76 + }) + + + const Andrea = new Student({ + name: 'Andrea', + age: 24, + location: 'Orlando', + previousBackground: 'student', + className: 'CS', + favSubjects: ['English', 'Econ', 'Marketing'], + grade: 76 + }) + + + const Ron = new Student({ + name: 'Ron', + age: 22, + location: 'Boston', + previousBackground: 'runner', + className: 'Programming', + favSubjects: ['AI', 'science', 'Mobile Tec'], + grade: 80 + }) + + const Nav = new ProjectManager({ + name: 'Nav', + location: 'NYC', + age: 30, + favLanguage: 'C++', + specialty: 'Servers', + catchPhrase: `I don't bite, unless`, + gradClassName: 'Javascript', + favInstructor: 'M' + }) + + const Louise = new ProjectManager({ + name: 'Louise', + location: 'Toronto', + age: 33, + favLanguage: 'Ruby', + specialty: 'Customer Applications', + catchPhrase: `Bit me and you'll see`, + gradClassName: 'Data Sci', + favInstructor: 'T' + }) + + const Hanna = new ProjectManager({ + name: 'Hanna', + location: 'Galveston', + age: 25, + favLanguage: 'Python', + specialty: 'cooking', + catchPhrase: `Let's cook some Python!`, + gradClassName: 'Python', + favInstructor: 'F' + }) + + + +console.log(T.location); +console.log(M.specialty); +console.log(Louise.favLanguage); +console.log(Hanna.standUp()); +console.log(Andrea.favSubjects); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..70e108cd4 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,9 +1,246 @@ -/* -Prototype Refactor -1. Copy and paste your code or the solution from yesterday - -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. +//Prototype Refactor +//1. Copy and paste your code or the solution from yesterday +/* + === 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(attributes){ +// this.createdAt = attributes.createdAt, +// this.name = attributes.name, +// this.dimensions = attributes.dimensions +// } +// GameObject.prototype = Object.create(GameObject.prototype); + +// GameObject.prototype.destroy= function(){ +// 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(stats){ +// GameObject.call(this, stats) +// this.healthPoints = stats.healthPoints + +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); + +// 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(attrib){ +// CharacterStats.call(this, attrib) +// this.team = attrib.team, +// this.weapons = attrib.weapons, +// this.language =attrib.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. + +//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. + + + + + 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.`; + }; + } + + class CharacterStats extends GameObject{ + constructor(stats){ + super(stats); + this.healthPoints = stats.healthPoints + } + takeDamage(){ + return `${this.name} took damage.` + }; + } + + + + class Humanoid extends CharacterStats{ + constructor(attrib){ + super(attrib); + this.team = attrib.team, + this.weapons = attrib.weapons, + this.language =attrib.language + + } + greet(){ + return `${this.name} offers a greeting in ${this.language}` + }; +} + + +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