From 4d73d7bcd862cfc3f017392e47baa25d48828cd5 Mon Sep 17 00:00:00 2001 From: Sara De La Cruz Date: Thu, 19 Sep 2019 13:37:15 -0500 Subject: [PATCH 1/3] prototype-refactor.js completed --- assignments/prototype-refactor.js | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..9ba87c1b8 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,99 @@ 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. */ + + +class GameObject { + constructor(gameAttributes) { + this.createdAt = gameAttributes.createdAt, + this.name = gameAttributes.name, + this.dimensions = gameAttributes.dimensions + } + destroy() { + return (`${this.name} was removed from the game`); + } +} + +class CharacterStats extends GameObject { + constructor(characterAttributes) { + super(characterAttributes); + this.healthPoints = characterAttributes.healthPoints + } + takeDamage() { + return (`${this.name} took damage.`); + } +} +class Humanoid extends CharacterStats { + constructor(humanoidAttributes) { + super(humanoidAttributes); + this.team = humanoidAttributes.team, + this.weapons = humanoidAttributes.weapons, + this.language = humanoidAttributes.language + } + 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. + From cc6bbfaee9601799b4c881880588725965e83799 Mon Sep 17 00:00:00 2001 From: Sara De La Cruz Date: Thu, 19 Sep 2019 15:54:28 -0500 Subject: [PATCH 2/3] lambda-classes.js completed --- assignments/code.js | 41 ++++++++++++ assignments/lambda-classes.js | 123 ++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 assignments/code.js diff --git a/assignments/code.js b/assignments/code.js new file mode 100644 index 000000000..f00ade769 --- /dev/null +++ b/assignments/code.js @@ -0,0 +1,41 @@ +function Parent(attributes) { + this.gender = attributes.gender; + this.age = attributes.age; + this.name = attributes.name; + this.homeTown = attributes.homeTown +} + +function Child(attributes) { + Parent.call(this, attributes); // binding to Parent + this.isChild = attributes.isChild; // a special attribute to Child + +} + +Parent.prototype.yabbaDabba = function () { + return 'Yabba dabba doo!'; +}; + +Parent.prototype.speak = function () { + return `Hello, my name is ${this.name}`; +}; + +Child.prototype = Object.create(Parent.prototype); +Child.prototype.checkIfChild = function () { + return `My name is ${this.name}.`;// \nAm I a Child? ${pebbles instanceof Child}.\nAm I a Parent? ${pebbles instanceof Parent}.`; +}; + + + + + +const fred = new Parent({ gender: 'Male', age: 35, name: 'Fred', homeTown: 'Bedrock' }); + +const wilma = new Parent({ gender: 'Female', age: 37, name: 'Wilma', homeTown: 'Bedrock' }); + +const pebbles = new Child({ gender: 'Female', age: 3, name: 'Pebbles', homeTown: 'Bedrock', isChild: true }); + +console.log("***** Child *****"); +console.log("5.", pebbles); +console.log("6.", pebbles.speak()); +console.log("7.", pebbles.checkIfChild()); +console.log("8.", pebbles.yabbaDabba()); \ No newline at end of file diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..73d441f18 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,124 @@ // CODE here for your Lambda Classes + +class Person { + constructor(personAttributes) { + this.name = personAttributes.name, + this.age = personAttributes.age, + this.location = personAttributes.location + } + speak() { + return (`Hello my name is ${this.name}, I am from ${this.location}`); + } +} + + +class Instructor extends Person { + constructor(attributes) { + super(attributes); + this.specialty = attributes.specialty, + this.favLanguage = attributes.favLanguage, + this.catchPhrase = attributes.catchPhrase, + this.gradingScale = attributes.gradingScale + } + demo() { + return (`Today we are learning about ${this.specialty}`) + } + grade() { + return (`${this.name} receives a perfect score on ${this.specialty}`); + } + score() { + if (this.gradingScale >= 70) { + return `Congratulations, you have graduated!` + } + `Still grading to determine if passing.` + } +} + + +class Students extends Instructor { + constructor(studentAttributes) { + super(studentAttributes); + this.previousBackground = studentAttributes.previousBackground, + this.classname = studentAttributes.classname, + this.favSubjects = studentAttributes.favSubjects + } + listsSubjects() { + return ['HTML', 'CSS', 'JavaScript'] + } + prassignment() { + return (`${this.name} has submitted a PR for ${this.specialty}`) + } + sprintChallenge() { + return (`${this.name} has begun sprint challenge on ${this.specialty} `); + } + score() { + if (this.gradingScale >= 70) { + return `Congratulations, you have graduated!` + } + `Still grading to determine if passing.` + } +} + +class Projectmanagers extends Instructor { + constructor(pmAttributes) { + super(pmAttributes); + this.gradClassName = pmAttributes.gradClassName, + this.favInstructor = pmAttributes.favInstructor, + this.channel = pmAttributes.channel + } + standUp() { + return (`${this.name} announces to ${this.channel}, @channel standby times!`) + } + debugsCode() { + return (`${this.name} debugs ${this.name}'s code on ${this.specialty}`) + } +} + +const user = new Person({ + name: 'Fred', + age: 45, + location: 'Bedrock', + catchPhrase: `it is what it is` + +}); + +const student = new Students({ + name: 'Jane', + location: 'Tampa', + age: 25, + favLanguage: 'JavaScript', + specialty: 'CSS', + previousBackground: 'teacher', + classname: 'Web24', + favSubjects: ['HTML', 'CSS', 'JavaScript'], + gradingScale: 95, +}); + +const instruct = new Instructor({ + name: 'Tina', + location: 'Utah', + age: 34, + favLanguage: 'HTML', + specialty: 'React', + catchPhrase: `Don't forget the homies` +}); + +const projectMag = new Projectmanagers({ + name: 'Tom', + location: 'San Francisco', + age: 34, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies`, + channel: 'Web24' +}); + +console.log(user.speak()); +console.log(instruct.demo()); +console.log(instruct.grade()); +console.log(student.listsSubjects()); +console.log(student.prassignment()); +console.log(student.sprintChallenge()); +console.log(projectMag.standUp()); +console.log(projectMag.debugsCode()); +console.log(student.score()); \ No newline at end of file From cb0d3d16190211d0e6acac4fe9046ea582e7fd38 Mon Sep 17 00:00:00 2001 From: Sara De La Cruz Date: Thu, 19 Sep 2019 16:34:03 -0500 Subject: [PATCH 3/3] challenge completed --- assignments/lambda-classes.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 73d441f18..668073a87 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -26,21 +26,17 @@ class Instructor extends Person { grade() { return (`${this.name} receives a perfect score on ${this.specialty}`); } - score() { - if (this.gradingScale >= 70) { - return `Congratulations, you have graduated!` - } - `Still grading to determine if passing.` - } + } -class Students extends Instructor { +class Students extends Person { constructor(studentAttributes) { super(studentAttributes); this.previousBackground = studentAttributes.previousBackground, this.classname = studentAttributes.classname, this.favSubjects = studentAttributes.favSubjects + this.gradingScale = studentAttributes.gradingScale } listsSubjects() { return ['HTML', 'CSS', 'JavaScript'] @@ -53,9 +49,9 @@ class Students extends Instructor { } score() { if (this.gradingScale >= 70) { - return `Congratulations, you have graduated!` + return `Congratulations, you have graduated!`; } - `Still grading to determine if passing.` + return `Still grading to determine if passing.`; } } @@ -91,7 +87,7 @@ const student = new Students({ previousBackground: 'teacher', classname: 'Web24', favSubjects: ['HTML', 'CSS', 'JavaScript'], - gradingScale: 95, + gradingScale: Math.floor(Math.random() * 100) + 1 }); const instruct = new Instructor({ @@ -121,4 +117,5 @@ console.log(student.prassignment()); console.log(student.sprintChallenge()); console.log(projectMag.standUp()); console.log(projectMag.debugsCode()); -console.log(student.score()); \ No newline at end of file +console.log(student.gradingScale); +console.log(student.score());