diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..573d378d6 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,134 @@ // CODE here for your Lambda Classes +class Person { + constructor(personStats) { + this.name = personStats.name; + this.age = personStats.age; + this.location = personStats.location; + this.gender = personStats.gender; + } + speak() { + return `Hello, my name is ${this.name}, I am from ${this.location}!` + } +} + +const poop = new Person({ + name: 'poop', + age: 'poopAge', + location: 'poopVille', + gender: 'poopSexual', +}); + + +const coolDude = new Person ({ + name: 'Fonzie', + age: 'Who cares?', + location: 'Where the wind takes me.', + gender: 'pansexual' +}); + +console.log(poop.speak()); +console.log(coolDude.speak()); + +class Instructor extends Person{ + constructor(instructorStats) { + super(instructorStats); + this.speciality = instructorStats.speciality; + this.favLanguage = instructorStats.favLanguage; + this.catchPhrase = instructorStats.catchPhrase; + } + demo(subject) { + return `Today we are learning about ${subject}.` + } + grade(student, subject) { + return `${student.name} recieves a very cool score on ${subject}.` + } +} + +const josh = new Instructor( { + name: 'Josh', + age: '30', + location: 'Mid-West', + gender: 'male', + speciality: 'being cool', + favLanguage: 'React', + catchPhrase :'Yo, good job there. That was well done.' +}); + +const obiwan = new Instructor( { + name: 'Obi-Wan', + age: '70', + location: 'Tatooine', + gender: 'male', + speciality: 'disappearing', + favLanguage: 'SandPeople', + catchPhrase : 'Trust in the force. I mean, I died but lol im a spirit cool amirite' +}); + +const poopMaster = new Instructor({ + name: 'poop', + age: 'poopAge', + location: 'poopVille', + gender: 'poopSexual', + speciality: 'pooping', + favLanguage: 'pooScript', + catchPhrase : 'Pooping feels good. And its good for you.' +}); + +console.log(poopMaster.demo("math")); + +class Student extends Person { + constructor(studentStats) { + super(studentStats); + this.previousBackground = studentStats.previousBackground; + this.className = studentStats.className; + this.favSubjects = studentStats.favSubjects; + } + listsSubjects(favSubjects) { + this.favSubjects.forEach(element => console.log(element)); + } + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}` + } + sprintChallenge(subject) { + return `${this.name} has begun sprint challenge on ${subject}` + } +} + +class ProjectManagers extends Instructor { + constructor(pmStats){ + super(pmStats); + this.gradClassName = pmStats.gradClassName; + this.favInstructor = pmStats.favInstructor; + } + standUp(channel) { + console.log(`${this.name} announces to ${channel}, @channel standy times!`) + } + debugsCode(student, subject) { + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`) + } + +} + +const daniel = new Student ({ + name: 'Daniel', + location: 'Florida', + age: '25', + gender: 'male', + previousBackground:'Python', + className: 'FSW_15', + favSubjects: ["Inheritance","Flexbox","Generator functions"], +}); + +const trevor = new ProjectManagers({ + name: 'Trevor', + location: 'behind you', + age: 'I dont Age', + gender: 'flexible', + specialty: 'Frontend development', + favLanguage: 'Javascript', + favSubjects: ['js', 'html', 'react'] + }); + + trevor.standUp('goodstuff'); + trevor.debugsCode(daniel, 'Javascript'); + daniel.listsSubjects(); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..44e5c2077 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -4,6 +4,186 @@ 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. +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 + * dimensions + * destroy() // prototype method -> returns the string: 'Object was removed from the game.' +*/ + +// make a parent constructor that builds out all the objects we will be using + +class gameObject { + constructor(gameObj) { + this.createdAt = gameObj.createdAt; + this.dimensions = gameObj.dimensions; + } + destroy() { + return `${this.name} was removed from the game ... yo.` + } +} //parent, base constructor + + + class characterStats extends gameObject { + constructor(charStats) { + super(charStats); + this.hp = charStats.hp; + this.name = charStats.name; + } + takeDamage() { + return `${this.name} took some damage, yo!` + + } + } + class Humanoid extends characterStats { + constructor(humanStats) { + super(humanStats); + this.faction = humanStats.faction; + this.weapons = humanStats.weapons; + this.language = humanStats.language; + } + greet() { + return `${this.name} offers a cool greeting in ${this.language}`; + + } + } + + // Hero - Ash + class Hero extends Humanoid { + constructor(heroObj){ + super(heroObj); + this.juice = heroObj.juice; + this.josh = heroObj.josh; + this.good = heroObj.good; + this.evil = heroObj.evil; + } + } + + // Villian - Trevor + class Villian extends Humanoid { + constructor(villianObj){ + super(villianObj); + this.juice = villianObj.juice; + this.josh = villianObj.josh; + this.good = villianObj.good; + this.evil = villianObj.evil; + } + } + /* + * 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 uncommenting these 3 objects and the list of console logs below: + + + const mage = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 1, + height: 1, + }, + hp: 5, + name: 'Bruce', + faction: 'Mage Guild', + weapons: [ + 'Staff of Shamalama', + ], + language: 'Common Toungue', + }); + + const swordsman = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 2, + height: 2, + }, + hp: 15, + name: 'Sir Mustachio', + faction: 'The Round Table', + weapons: [ + 'Giant Sword', + 'Shield', + ], + language: 'Common Toungue', + }); + + const archer = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + hp: 10, + name: 'Lilith', + faction: 'Forest Kingdom', + weapons: [ + 'Bow', + 'Dagger', + ], + language: 'Elvish', + }); + + const hero = new Hero({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + hp: 200, + juice: 400, + name: 'Ash', + faction: 'Really good programmers', + weapons: [ + 'Shame', + 'Josh', + ], + language: 'All Known Languages', + }); + + const villian = new Villian({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + hp: 100, + juice: 1000, + name: 'Trevor', + faction: 'Really good programmers', + weapons: [ + 'Evil Smile', + 'Rant', + 'Being super nice but actually is planning something evil' + ], + language: 'html', + }); + + console.log(mage.createdAt); // Today's date + console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } + console.log(swordsman.hp); // 15 + console.log(mage.name); // Bruce + console.log(swordsman.faction); // 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. + + //check hero stuff + console.log(hero.createdAt); //when did he git created? + console.log(hero.name); //did ash pop out? + console.log(hero.juice); // how much juice, gamerfuel does ash have? +