diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..6c8386f08 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,246 @@ // CODE here for your Lambda Classes + +class Person { + constructor(personAttrs) { + //set up properties + this.name = personAttrs.name; + this.age = personAttrs.age; + this.location = personAttrs.location; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}` + } +} +class Instructor extends Person { + constructor(instructorAttrs) { + super(instructorAttrs); + this.specialty = instructorAttrs.specialty; + this.favLanguage = instructorAttrs.favLanguage; + this.catchPhrase = instructorAttrs.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 Person { + constructor(studentAttrs) { + super(studentAttrs); + this.previousBackground = studentAttrs.previousBackground; + this.className = studentAttrs.className; + this.favSubjects = studentAttrs.favSubjects; + } + listSubjects() { + this.favSubjects.map(item => console.log(item)); + } + + PRAssigmment() { + return `${this.name} has submitted a PR for ${subject}`; + } + + sprintChallenge() { + return `${student.name} has begun spring challenge on ${subject}`; + } +} + +class TeamLead extends Instructor { + constructor(teamLeadAttrs) { + super(teamLeadAttrs); + this.gradclassName = teamLeadAttrs.gradclassName; + this.favInstructor = teamLeadAttrs.favInstructor; + } + standup() { + return `${this.name} announces to ${channel}, @channel standy times!`; + } + + debugsCode() { + return `${this.name} debugs ${student.name}'s code on ${subject}`; + } +} + +// Instructors +const fred = new Instructor({ + name: 'Fred', + location: 'Bedrock', + age: 37, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `"Yabba Dabba Doo"` +}); + +const wilma = new Instructor({ + name: 'Wilma', + location: 'Bedrock', + age: 32, + favLanguage: 'Python', + specialty: 'Back-end', + catchPhrase: `"And you know this....... MAN!"` +}); + +const barney = new Instructor({ + name: 'Barney', + location: 'Brooklyn, NY', + age: 33, + favLanguage: 'JavaScript', + specialty: 'Full - Stack', + catchPhrase: `"What you talking bout, Willis?"` +}); + +// Instructor 1 test +console.log(fred.speak()); +console.log( + `${fred.name}'s Bio + ${fred.name} is ${fred.age} years old. + ${fred.name}'s favorite language is ${fred.favLanguage}. + He speacializes in ${fred.specialty} development. + His catch phrase is from his favorite cartoon the Flintstones, ${fred.catchPhrase}. ` +); +// Instructor 2 test +console.log(wilma.speak()); +console.log( + `${wilma.name}'s Bio + ${wilma.name} is ${wilma.age} years old. + ${wilma.name}'s favorite language is ${wilma.favLanguage}. + She speacializes in ${wilma.specialty} development. + Her catch phrase is from her favorite movie Friday, ${wilma.catchPhrase}. ` +); +// Instructor 3 test +console.log(barney.speak()); +console.log( + `${barney.name}'s Bio + ${barney.name} is ${barney.age} years old. + ${barney.name}'s favorite language is ${barney.favLanguage}. + He speacializes in ${barney.specialty} development. + His catch phrase is from his favorite sitcom Different Strokes, ${barney.catchPhrase}. ` +); + + + + +// Team Leads +const chrisPaul = new TeamLead({ + name: "Chris Paul", + location: "OKC", + age: 34, + gradclassName: "Web2005", + favInstructor: "Doc Rivers", + specialty: "Front-end", + catchPhrase: '"Show me the money!!!!"', + favLanguage: "JavaScript" +}); + +const jasonKidd = new TeamLead({ + name: "Jason Kidd", + location: "New Jersey", + age: 46, + gradclassName: "Web1994", + favInstructor: "Rick Carlisle", + specialty: "Flex-box", + catchPhrase: '"I must break you"', + favLanguage: "LESS" +}); + + +const steveNash = new TeamLead({ + name: "Steve Nash", + location: "Phoenix", + age: 45, + gradclassName: "Web2005", + favInstructor: "Mike D'Antoni", + specialty: "Databases", + catchPhrase: '"Did I do that?"', + favLanguage: "PHP" +}); + +// Team Lead 1 test +console.log(jasonKidd.speak()); +console.log(`${jasonKidd.name}'s Bio +Jason is ${jasonKidd.age} years old. +his favorite instructor is ${jasonKidd.favInstructor} +He specializes in ${jasonKidd.specialty} +His favorite language is ${jasonKidd.favLanguage}. +His catch phrase is from the movie Rocky IV, ${jasonKidd.catchPhrase} +${jasonKidd.name}'s grad class is ${jasonKidd.gradclassName}`); + +// Team Lead 2 test +console.log(chrisPaul.speak()); +console.log(`${chrisPaul.name}'s Bio +Chris is ${chrisPaul.age} years old. +his favorite instructor is ${chrisPaul.favInstructor}. +He specializes in ${chrisPaul.specialty}. +His favorite language is ${chrisPaul.favLanguage}. +His catch phrase is from the movie Jerry Maguire, ${chrisPaul.catchPhrase}. +${chrisPaul.name}'s grad class is ${chrisPaul.gradclassName}`); + +// Team Lead 3 test +console.log(steveNash.speak()); +console.log(`${steveNash.name}'s Bio +Steve is ${steveNash.age} years old. +his favorite instructor is ${steveNash.favInstructor} +He specializes in ${steveNash.specialty} +His favorite language is ${steveNash.favLanguage}. +His catch phrase is from the sitcom Family Matters, ${steveNash.catchPhrase} +${steveNash.name}'s grad class is ${steveNash.gradclassName}`); + +// Students +const dwayneWayne = new Student({ + name: "Dwayne Wayne", + age: 54, + location: "Brooklyn, NY", + previousBackground: "80's sitcom star", + className: "WEB1", + favSubjects: [`HTML, CSS, and JavaScript`] + +}); + +const ronJohnson = new Student({ + name: "Ron Johnson", + age: 56, + location: "Detroit, Mi", + previousBackground: "80'sitcom star", + className: "WEB2", + favSubjects: [`CSS", and Python`], + +}); + +const whitleyGilbert = new Student({ + name: "Whitley Gilbert", + age: 57, + location: "Richtown, USA", + previousBackground: "80's sitcom star", + className: "WEB1", + favSubjects: [`Python, CSS, and Java`], +}); + +// Student 1 test +console.log(dwayneWayne.speak()); +console.log( + `${dwayneWayne.name}'s Bio +${dwayneWayne.name} is ${dwayneWayne.age} years old. +${dwayneWayne.name} has a background as a ${dwayneWayne.previousBackground}. +He is currently enrolled in ${dwayneWayne.className}. +${dwayneWayne.name}'s favorite subjects so far are ${dwayneWayne.favSubjects}.` +); + +// Student 2 test +console.log(ronJohnson.speak()); +console.log( + `${ronJohnson.name}'s Bio +${ronJohnson.name} is ${ronJohnson.age} years old. +${ronJohnson.name} has a background as a ${ronJohnson.previousBackground}. +He is currently enrolled in ${ronJohnson.className}. +${ronJohnson.name}'s favorite subjects so far are ${ronJohnson.favSubjects}.` +); + +// Student 3 test +console.log(whitleyGilbert.speak()); +console.log( + `${whitleyGilbert.name}'s Bio +${whitleyGilbert.name} is ${whitleyGilbert.age} years old. +${whitleyGilbert.name} has a background as a ${whitleyGilbert.previousBackground}. +He is currently enrolled in ${ronJohnson.className}. +${whitleyGilbert.name}'s favorite subjects so far are ${whitleyGilbert.favSubjects}.` +); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..9ab226c35 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,178 @@ 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(gamAttributes) { +// this.createAt = gamAttributes.createdAt; +// this.name = gamAttributes.name; +// this.dimensions = gamAttributes.dimensions; +// } +// GameObject.prototype.destroy = function() { +// return `${this.name} was removed from the game`; +// } + + class GameObject { + constructor(gamAttributes) { + this.createdAt = gamAttributes.createdAt; + this.name = gamAttributes.name; + this.dimensions = gamAttributes.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(charAttributes) { +// this.healthPoints=charAttributes.healthPoints; +// GameObject.call (this, charAttributes); +// } +// CharacterStats.prototype = Object.create(GameObject.prototype); +// CharacterStats.prototype.takeDamage= function() { +// return `${this.name} took damage.` +// } + +class CharacterStats extends GameObject { + constructor(csAttr) { + super(csAttr) + // set properties + this.healthPoints = csAttr.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(humanAttributes) { +// this.team = humanAttributes.team; +// this.weapons = humanAttributes.weapons; +// this.language = humanAttributes.language; +// CharacterStats.call (this, humanAttributes); +// } +// Humanoid.prototype = Object.create(CharacterStats.prototype); +// Humanoid.prototype.greet = function() { +// return `${this.name} offers a greeting in ${this.language}`; +// } + + class Humanoid extends CharacterStats{ + constructor(humanAttributes) { + super(humanAttributes); + this.team = humanAttributes.team; + this.weapons = humanAttributes.weapons; + this.language = humanAttributes.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