diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..355668d51 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,135 @@ // CODE here for your Lambda Classes + +// === Person CONSTRUCTOR === +class Person { + constructor(obj) { + this.name = obj.name; + this.age = obj.age; + this.location = obj.location; + this.gender = obj.gender; + } + // === Methods === + speak(){ + return `Hello my name is ${this.name}, and I am from ${this.location}` + } +} + +// === Instructor CONSTRUCTOR === +class Instructor extends Person { + constructor(obj) { + super(obj); + this.specialty = obj.specialty; + this.favLanguage = obj.favLanguage; + this.catchPhrase = obj.catchPhrase; + } + // Methods + demo(subject){ + return `Today we are going to learn about ${subject}` + }; + grade(student,subject){ + return `${student} receives a perfect score on ${subject}` + }; + graded(student,grade){ + + if (grade >= 70) { + return `Congrats ${student} you graduated!` + } else { + return `Sorry you have to retake this course.` + } + } +} + +// === Student CONSTRUCTOR === +class Student extends Instructor { + constructor(obj) { + super(obj); + this.previousBackground = obj.previousBackground; + this.className = obj.className; + this.favSubjects = obj.favSubjects; + this.grade = obj.grade; + } + // Methods + listsSubjects(){ + return this.favSubjects; + }; + PRAssignment(subject){ + return `${this.name} has submittd a PR for ${subject}` + }; + sprintChallenge(subject){ + return `${this.name} has begun sprint sprint chellenge on ${subject}` + }; +} + +// === Project Manager CONSTRUCTOR === +class Projectm extends Student { + constructor(obj) { + super(obj); + this.gradClassName = obj.gradClassName; + this.favInstructor = obj.favInstructor; + } + // Methods + standUp(name, channel){ + return `${name} announces to ${channel}, @channel standy times! ` + }; + debugCode(name, subject){ + return `${name} debugs ${this.name}'s code on ${subject}'` + } + +} + + + +// New objects created + +const liz_B = new Projectm({ + name: "Lizzy B", + age: 27, + gender: "Female", + location: "Portland, OR", + previousBackground: "Biology/Health Science grad", + className: "WEB12", + favSubjects: ["CSS","React","Ternaries","SQL","Node"], +}) + +const christian_ipanaque = new Student({ + name: "Christian Ipanaque", + age: 32, + gender: "Male", + location: "Seattle, WA", + previousBackground: "Server Hardware Technician", + className: "WEB18", + favSubjects: ["Computer Science","Redux","Algorithms","Data Structures","Computer Architecture"], +}) + +const leslie_t = new Student({ + name: "Leslie Thompson", + age: 31, + location: "San Francisco, CA", + gender: "F", + previousBackground: "Retail Management", + className: "Web18", + favSubjects: ["CSS", "JavaScript", "Cooking", "Biology"] +}); + +const scubaSteve = new Projectm({ + name: "Steve Lanier", + age: 29, + gender: "Male", + location: "Portland, OR", + previousBackground: "Jack of all trades", + className: "WEB18", + favSubjects: ["The ladies",,"Barbershop Quartets","Sleeping","Weekend parties","Weekday parties","Saving the world before bedtime"], + catchPhrase: "PC load-letter? The f*** does that mean?" +}) + + +// checking objects, remove commets to check code +console.log(liz_B.graded('Oscar',80)); +console.log(scubaSteve.PRAssignment('Javascript')) + + + + + + +// diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..37515b2ba 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,9 +1,216 @@ -/* +/* Prototype Refactor 1. Copy and paste your code or the solution from yesterday +// === GameObject === +function GameObject(obj){ + // * createdAt + this.createdAt = obj.createdAt; + // * name + this.name = obj.name; + // * dimensions (These represent the character's size in the video game) + this.dimensions = obj.dimensions; +} + +GameObject.prototype.destroy = function(){ + return `${this.name} was removed from the game.`; +} + +// === CharacterStats === +function CharacterStats(obj){ + this.healthPoints = obj.healthPoints; + GameObject.call(this,obj); +} + +CharacterStats.prototype = Object.create(GameObject.prototype); + + CharacterStats.prototype.takeDamage = function() { + return `${this.name} took damage.`; +} + + //HUMANOID CONSTRUCTOR'S TERRITORY +function Humanoid(hobj) { + this.team = hobj.team; + this.weapons = hobj.weapons; + this.language = hobj.language; + CharacterStats.call(this, hobj); +} + + Humanoid.prototype = Object.create(CharacterStats.prototype); + + Humanoid.prototype.greet = function() { + return `${this.name} offers a greeting in ${this.language}.` +} + +// 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. */ + +// === GameObject === + +class GameObject { + constructor(obj) { + this.createdAt = obj.createdAt; + this.name = obj.name; + this.dimensions = obj.dimensions; + } + //Methods + destroy(){ + return `${this.name} was removed from the game.` + } +} + +class CharacterStats extends GameObject { + constructor(obj) { + super(obj); + this.healthPoints = obj.healthPoints; + } + //Methods + takeDamage(){ + return `${this.name} took damage.` + } +} + + +class Humanoid extends CharacterStats{ + constructor(obj) { + super(obj); + this.team = obj.team; + this.weapons = obj.weapons; + this.language = obj.language; + } + //Methods + 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.