From 4f2b08562b2e34d62db57be44524d895f154d5e1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 24 May 2018 14:43:01 -0500 Subject: [PATCH 1/3] Stuck on prototype-refactor.js --- assignments/prototype-refactor.js | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..b7c5829ed 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,41 @@ // Today 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. -function GameObject(options) { - this.createdAt = options.createdAt; - this.dimensions = options.dimensions; -} - -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; -}; +class GameObject { + constructor(goAttributes) { + this.createdAt = goAttributes.createdAt; + this.dimensions = goAttributes.dimensions; + } -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); - this.hp = characterStatsOptions.hp; - this.name = characterStatsOptions.name; + destroy() { + return `Object was removed from the game.`; + } } -CharacterStats.prototype = Object.create(GameObject.prototype); +class CharacterStats extends GameObject { + constructor(csAttributes){ + super(csAttributes); + this.hp = csAttributes.hp; + this.name = csAttributes.name; + } -CharacterStats.prototype.takeDamage = function() { - return `${this.name} took damage.`; -}; - -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); - this.faction = humanoidOptions.faction; - this.weapons = humanoidOptions.weapons; - this.language = humanoidOptions.language; + takeDamage(){ + return `${this.name} took damage.`; + } } -Humanoid.prototype = Object.create(CharacterStats.prototype); +class Humanoid extends CharacterStats { + prototype(hAttributes) { + super(hAttributes); + this.faction = hAttributes.faction; + this.weapons = hAttributes.weapons; + this.language = hAttributes.language; + } -Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; -}; + greet() { + return `${this.name} offers a greeting in ${this.language}.`; + } +} const mage = new Humanoid({ createdAt: new Date(), From f938b3aff25f2e0a9c595359fb537a75eb113531 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 24 May 2018 15:45:15 -0500 Subject: [PATCH 2/3] added classes to lambda-classes.js --- assignments/lambda-classes.js | 84 ++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..de1b9f31b 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,83 @@ -// CODE here for your Lambda Classes +class Person { + // name age location gender + constructor(pAttributes){ + this.name = pAttributes.name; + this.age = pAttributes.age; + this.location = pAttributes.location; + this.gender = pAttributes.gende; + } + + // This method logs out a phrase `Hello my name is Fred, I am from Bedrock` where `name` and `location` are the object's own props + speak(){ + return `Hello my name is ${this.name}, I am from ${this.location}`; + } + +} // Person + +class Instructor extends Person { + // specialty favLanguage catchPhrase + constructor(iAttributes) { + super(iAttributes); + this.specialty = iAttributes.specialty; + this.favLanguage = iAttributes.favLanguage; + this.catchPhrase = iAttributes.catchPhrase; + } + + // receives a `subject` string as an argument and logs out the phrase 'Today we are learning about {subject}' where subject is the param passed in. + demo(subject) { + return `Today we are learning about ${subject}`; + } + + // `grade` receives a `student` object and a `subject` string as arguments and logs out '{student.name} receives a perfect score on {subject}' + grade(student, subject) { + return `${student.name} recieves a perfect score on ${subject}` + } + +}// Instructor + +class Student extends Person { + // previousBackground className favSubjects + constructor(sAttributes) { + super(sAttributes); + this.previousBackground = sAttributes.previousBackground; + this.className = sAttributes.className; + this.favSubjects = sAttributes.favSubjects; + } + // a method that logs out all of the student's favoriteSubjects one by one. + listsSubjects(){ + for(let i = 0; i < this.favSubjects.length; i++){ + console.log(this.favSubjects[i]); + } + } + + // a method that receives a subject as an argument and logs out that the `student.name has submitted a PR for {subject}` + PRAssignment(subject){ + return `${this.name} has submitted a PR for ${subject}`; + } + + // similar to PRAssignment but logs out `student.name has begun spring challenge on {subject}` + sprintChallenge(subject){ + return `${this.name} has begun spring challenge on ${subject}`; + } + +} // Student + +class ProjectManager extends Instructor { + constructor(pmAttributes) { + // gradClassName favInstructor + super(pmAttributes); + this.gradClassName = pmAttributes.gradClassName; + this.favInstructor = pmAttributes.favInstructor; + } + + // a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​ + standUp(slackChannel){ + return `${this.name} announces to ${slackChannel}, @channel standy times!`; + } + + // a method that takes in a student object and a subject and logs out `{name} debugs {student.name}'s code on {subject}` + debugsCode(student, subject){ + return `${this.name} debugs ${student.name}'s conde on ${subject}`; + } + +} // Project Manager \ No newline at end of file From 9555f5360acec04404eca5791cc3a57adb827a3f Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 24 May 2018 17:38:04 -0500 Subject: [PATCH 3/3] lambda-classes.js students added, methods tested in console --- assignments/lambda-classes.js | 113 ++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index de1b9f31b..3aed6c20d 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1,3 +1,4 @@ +// -CLASSES- class Person { // name age location gender constructor(pAttributes){ @@ -41,12 +42,13 @@ class Student extends Person { super(sAttributes); this.previousBackground = sAttributes.previousBackground; this.className = sAttributes.className; - this.favSubjects = sAttributes.favSubjects; + this.favoriteSubjects = sAttributes.favoriteSubjects; } + // a method that logs out all of the student's favoriteSubjects one by one. listsSubjects(){ - for(let i = 0; i < this.favSubjects.length; i++){ - console.log(this.favSubjects[i]); + for(let i = 0; i < this.favoriteSubjects.length; i++){ + console.log(this.favoriteSubjects[i]); } } @@ -57,7 +59,7 @@ class Student extends Person { // similar to PRAssignment but logs out `student.name has begun spring challenge on {subject}` sprintChallenge(subject){ - return `${this.name} has begun spring challenge on ${subject}`; + return `${this.name} has begun sprint challenge on ${subject}`; } } // Student @@ -80,4 +82,105 @@ class ProjectManager extends Instructor { return `${this.name} debugs ${student.name}'s conde on ${subject}`; } -} // Project Manager \ No newline at end of file +} // Project Manager + +// -OBJECTS- +// Students name age location gender previousBackground className favSubjects +const morty = new Student({ + "name": "Morty Smith", + "age": "14", + "location": "Chicago", + "gender": "M", + "previousBackground": ["Interdimentional Travel", "Puberty"], + "className": "Computer Science Immersive", + "favoriteSubjects": ["HTML", "CSS"] +}); + +const summer = new Student({ + "name": "Summer Smith", + "age": "18", + "location": "Chicago", + "gender": "F", + "previousBackground": ["Not Much"], + "className": "Computer Science Immersive", + "favoriteSubjects": ["Lunch", "Mall"] +}); + +const abrodolph = new Student({ + "name": "Abrodolph Lincler", + "age": "47", + "location": "Rick's Lab", + "gender": "M", + "previousBackground": ["Morally Confused"], + "className": "Computer Science Immersive", + "favoriteSubjects": ["Moral-Neutrality", "AI"] +}); + +// Teachers name age location gender specialty favLanguage catchPhrase +const rick = new Instructor({ + "name": "Rick Sanchez", + "age": "70", + "location": "Earth", + "gender": "M", + "specialty": "Inventor", + "favLanguage": "Bird Person", + "catchPhrase": "Wubba lubba dub-dub!" +}); + +const eyehole = new Instructor({ + "name": "Eyehole Man", + "age": "26", + "location": "Earth", + "gender": "M", + "specialty": "Roughing up 'Eyehole Cerial' fans", + "favLanguage": "Megaphone", + "catchPhrase": "Get up on out of hter with my Eyeholes." +}); + +const goldenfold = new Instructor({ + "name": "Mr. Goldenfold", + "age": "48", + "location": "Earth", + "gender": "M", + "specialty": "Algebra", + "favLanguage": "Python", + "catchPhrase": "My lust... My greed... I deserve this!" +}); + + +// ProjectManagers name age location gender specialty favLanguage catchPhrase gradClassName favInstructor +const albert = new ProjectManager({ + "name":"Albert Einstein", + "age":"76", + "location":"Deceased", + "gender":"M", + "specialty":"Space Time", + "favLanguage":"Basic", + "catchPhrase":"The difference between stupidity and genious is that genious has it's limits", + "gradClassName":"CS11", + "favInstructor":"eyehole" +}); + +const kyle = new ProjectManager({ + "name":"Kyle", + "age":"30", + "location":"Rick's Microverse", + "gender":"M", + "specialty":"Miniverse Citizen", + "favLanguage":"Ruby", + "catchPhrase":"That just sounds like slavery with ex... tra... steps.", + "gradClassName":"CS11", + "favInstructor":"goldenfold" +}); + +const xenon = new ProjectManager({ + "name":"Dr. Xenon Bloom", + "age":"78", + "location":"Anatomy Park", + "gender":"M", + "specialty":"Running Anatomy Park", + "favLanguage":"JSON", + "catchPhrase":"The digestive tract is the body's evacuation route....get it?", + "gradClassName":"CS11", + "favInstructor":"rick" +}); \ No newline at end of file