diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..6276370db 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,131 @@ // CODE here for your Lambda Classes + +class Person { + constructor(attribute) { + this.name = attribute.name; + this.age = attribute.age; + this.location = attribute.location; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}. `; + } +} + +class Instructor extends Person { + constructor(attribute) { + super(attribute); + this.specialty = attribute.specialty; + this.favLanguage = attribute.favLanguage; + this.catchPhrase = attribute.catchPhrase; + } + demo(subject) { + return `Today we are learning about ${subject}.`; + } + grade(student, subject) { + return `${student.name} receives a perfect score on ${this.subject}!`; + } +} + +class Student extends Person { + constructor(attribute) { + super(attribute); + this.previousBackground = attribute.previousBackground; + this.className = attribute.className; + this.favSubjects = attribute.favSubjects; + } + listsSubjects(favSubjects) { + return this.favSubjects; + } + PRAssignment(subject) { + return `${this.name} has submitted a PR Assignment for ${subject}.`; + } + sprintChallenge(subject) { + return `${this.name} has begun the sprint challenge on ${subject}!`; + } +} + +class ProjectManager extends Instructor { + constructor(attribute) { + super(attribute); + this.gradClassName = attribute.gradClassName; + this.favInstructor = attribute.favIntructor; + } + standUp(channel) { + return `${this.name} announces to ${channel}, @channel standy times!`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student}'s code on ${subject}.`; + } +} + +const student_one = new Student({ + name: "Greg", + age: 30, + location: "Austin", + previousBackground: "Uber", + className: "Javascript II", + favSubjects: ["HTML", "Javascript", "CS"] +}); + +const student_two = new Student({ + name: "Colin", + age: 28, + location: "Salt Lake City", + previousBackground: "Sales", + className: "Javascript II", + favSubjects: ["Javascript", "Redux"] +}); + +const student_three = new Student({ + name: "Eric", + age: 22, + location: "San Antonio", + previousBackground: "Retail", + className: "Javascript II", + favSubjects: ["HTML", "CSS", "npm"] +}); + +const instructor_one = new Instructor({ + name: "Brit Demming", + age: 31, + location: "Canada", + specialty: "Keepin' it real", + favLanguage: "Javascript, HTML, CSS", + catchPhrase: "You're gonna know all about my pets" +}); + +const instructor_two = new Instructor({ + name: "Ryan Hamblin", + age: 32, + location: "Salt Lake City", + specialty: "Prototypical Inheritance", + favLanguage: "Javascript, React", + catchPhrase: "Put the keys in the car" +}); + +const projectManager_one = new ProjectManager({ + name: "Don Whitely", + age: 40, + location: "Indianapolis", + specialty: "Troubleshooting", + favLanguage: "React, Python", + catchPhrase: "Hold em' or Fold em'", + gradClassName: "Web13", + favInstructor: "James Starks" +}); + +const projectManager_two = new ProjectManager({ + name: "Joseph Hayden", + age: 30, + location: "Chicago", + specialty: "Keepin' it real", + favLanguage: "Javascript, Python", + catchPhrase: "Wubba Lubba Javascript", + gradClassName: "Web18", + favInstructor: "Brit Demming" +}); + +console.log(student_three.PRAssignment("CSS")); +console.log(projectManager_one.standUp("Web24")); +console.log(projectManager_two.debugsCode("Greg", "CSS")); +console.log(instructor_two.demo("callback functions")); diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..86fbe6bee 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,124 @@ 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(attribute) { + this.createdAt = attribute.createdAt; + this.name = attribute.name; + this.dimensions = attribute.dimensions; + } // closes constructor + // methods go here + 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(stats) { + super(stats); + this.healthPoints = stats.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 + */ + +class Humanoid extends CharacterStats { + constructor(profile) { + super(profile); + this.team = profile.team; + this.weapons = profile.weapons; + this.language = profile.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.