From fae9676d0896c531de955e5fa673e48001ed8fe8 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 09:05:41 -0600 Subject: [PATCH 1/7] Begin JavaScript IV --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2c59e6c4f..b8db05999 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Dominique + # JavaScript IV This challenge focuses on classes in JavaScript using the new `class` keyword. From 429ba3eb50596445f6ad1e7a81910d7150816b21 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 09:50:02 -0600 Subject: [PATCH 2/7] Added code from previous project --- assignments/prototype-refactor.js | 186 ++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..fb887cd07 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,189 @@ 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. */ + + + + /******************* COPIED CODE BELOW *************************/ + + + + + +/* + Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy. + + In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. + + At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions. + + Each constructor function has unique properties and methods that are defined in their block comments below: +*/ + +/* + === 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.` +*/ +function GameObject(attr){ + this.createdAt = attr.createdAt; + this.name = attr.name; + this.dimensions = attr.dimensions; + } + GameObject.prototype.destroy = function(){ + 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 + */ + function CharacterStats(attr){ + this.healthPoints = attr.healthPoints; + GameObject.call(this, attr); + } + CharacterStats.prototype = Object.create(GameObject.prototype); + CharacterStats.prototype.takeDamage = function(){ + 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 + */ + function Humanoid(attr){ + this.team = attr.team; + this.weapons = attr.weapons; + this.language = attr.language; + CharacterStats.call(this,attr); + } + + Humanoid.prototype = Object.create(CharacterStats.prototype); + Humanoid.prototype.greet = function(){ + return `${this.name} offers a greeting in ${this.language}`; + } + + + + /******************* STRETCH CONSTRUCTORS *******************/ + + + function Villain(attr){ + Humanoid.call(this, attr); + } + + Villain.prototype = Object.create(Humanoid.prototype); + Villain.prototype.foo =function(hero){ + return `${this.name} used ${this.weapons} and reduced ${hero} opponents healthPoints by 5`; + } + + function Hero(attr){ + Humanoid.call(this, attr); + } + + Hero.prototype = Object.create(Humanoid.prototype); + Hero.prototype.bar =function(villain){ + return `${this.name} used ${this.weapons} and reduced ${villain} opponents healthPoints by 10`; + } + + + /* + * 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', + }); + + const villain = new Villain({ + healthPoints: 10, + name: 'bowser', + weapons: [ + 'breath of fire' + ] + }); + + const hero = new Hero({ + healthPoints: 25, + name: 'yoshi', + weapons: [ + 'tongue of death' + ] + }); + + 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. + + console.log(villain.foo()); + console.log(hero.bar()); + console.log(villain.destroy(hero)); + // Stretch task: + // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. + // * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0; + // * Create two new objects, one a villain and one a hero and fight it out with methods! \ No newline at end of file From c932e7f1948de4b7952a3a403d73f86e4e83768e Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 13:53:02 -0600 Subject: [PATCH 3/7] skeleton of lambda-classes completed --- .vscode/settings.json | 3 ++ assignments/lambda-classes.js | 97 +++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..78629c375 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,98 @@ // CODE here for your Lambda Classes + +class Person{ + constructor(attr){ + this.name = attr.name; + this.age = attr.age; + this.location = attr.location; + } + speak(){ + console.log(`Hello, my name is ${this.name}, I am from ${this.location}`); + } +} + +class Instructor extends Person{ + constructor(attr){ + super(attr); + this.specialty = attr.specialty; + this.favLanguage = attr.favLanguage; + this.catchPhrase = attr.catchPhrase; + } + demo(subject){ + console.log(`Today we are learning about ${subject}`); + } +} + +class Student extends Instructor{ + constructor(attr){ + super(attr); + this.previousBackground = attr.previousBackground; + this.className = attr.className; + this.favSubject = attr.favSubject; + } + listSubjects(){ + console.log(`My favorite subjects are ${this.favSubject}`); + } + PRAssignment(subject){ + console.log(`${this.name} has submitted a PR for ${subject}`); + } + sprintChallange(subject){ + console.log(`${this.name} has begun the sprint challenge on ${this.subject}`); + } +} + + +class ProjectManager extends Instructor{ + constructor(attr){ + super(attr); + this.grandClassName = attr.grandClassName; + this.favInstructor = attr.favInstructor; + } + standup(slack){ + console.log(`${this.name} announces to ${channel}, @channel standy times!`); + } + debugCode(student, subject){ + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`); + } +} + + +const instructor = new Instructor({ + name: 'Britt', + age: 30, + location: 'Canada', + specialty: 'redux', + favLanguage: 'JavaScript', + catchPhrase: 'write it in the thread' +}) + +const student = new Student({ + name: 'Dominique', + age: 27, + location: 'Utah', + specialty: 'note taking', + favLanguage: 'JavaScript', + catchPhrase: '', + previousBackground: 'Exercise Physiology', + className: 'WEB23', + favSubject: 'CSS' +}) + +const pm = new ProjectManager({ + name: 'Steven', + age: 30, + location: 'Ohio', + specialty: 'redux', + favLanguage: 'Python', + catchPhrase: 'Im so proud of you guys', + grandClassName: 'CS1', + favInstructor: 'Britt' +}) + + +console.log(instructor.demo()); +console.log(student.listSubjects()); +console.log(student.PRAssignment()); +console.log(student.sprintChallange()); +console.log(pm.standup()); +console.log(pm.debugCode()); \ No newline at end of file From b2ca5b39f30e933b98479bf3af13ad09aea8d6b6 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 14:29:39 -0600 Subject: [PATCH 4/7] protoype-refactor completed --- assignments/prototype-refactor.js | 83 ++++++++++++++++--------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index fb887cd07..548d14825 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -33,13 +33,15 @@ Prototype Refactor * dimensions (These represent the character's size in the video game) * destroy() // prototype method that returns: `${this.name} was removed from the game.` */ -function GameObject(attr){ - this.createdAt = attr.createdAt; - this.name = attr.name; - this.dimensions = attr.dimensions; - } - GameObject.prototype.destroy = function(){ - return `${this.name} was removed from the game.`; +class GameObject{ + constructor(attr){ + this.createdAt = attr.createdAt; + this.name = attr.name; + this.dimensions = attr.dimensions; + } + destroy(){ + return `${this.name} was removed from the game.`; + } } /* === CharacterStats === @@ -47,14 +49,16 @@ function GameObject(attr){ * takeDamage() // prototype method -> returns the string ' took damage.' * should inherit destroy() from GameObject's prototype */ - function CharacterStats(attr){ - this.healthPoints = attr.healthPoints; - GameObject.call(this, attr); - } - CharacterStats.prototype = Object.create(GameObject.prototype); - CharacterStats.prototype.takeDamage = function(){ - return `${this.name} took damage`; + class CharacterStats extends GameObject{ + constructor(attr){ + super(attr); + this.healthPoints = attr.healthPoints; + } + takeDamage(){ + return `${this.name} took damage`; + } } + /* === Humanoid (Having an appearance or character resembling that of a human.) === * team @@ -64,40 +68,41 @@ function GameObject(attr){ * should inherit destroy() from GameObject through CharacterStats * should inherit takeDamage() from CharacterStats */ - function Humanoid(attr){ - this.team = attr.team; - this.weapons = attr.weapons; - this.language = attr.language; - CharacterStats.call(this,attr); + class Humanoid extends CharacterStats{ + constructor(attr){ + super(attr); + this.team = attr.team; + this.weapons = attr.weapons; + this.language = attr.language; + } + greet(){ + return `${this.name} offers a greeting in ${this.language}`; + } } - - Humanoid.prototype = Object.create(CharacterStats.prototype); - Humanoid.prototype.greet = function(){ - return `${this.name} offers a greeting in ${this.language}`; - } - - /******************* STRETCH CONSTRUCTORS *******************/ - function Villain(attr){ - Humanoid.call(this, attr); - } - - Villain.prototype = Object.create(Humanoid.prototype); - Villain.prototype.foo =function(hero){ - return `${this.name} used ${this.weapons} and reduced ${hero} opponents healthPoints by 5`; + class Villain extends Humanoid{ + constructor(attr){ + super(attr); + } + foo(){ + return `${this.name} used ${this.weapons} and reduced ${hero} opponents healthPoints by 5`; + } } + - function Hero(attr){ - Humanoid.call(this, attr); + class Hero extends Humanoid{ + constructor(attr){ + super(attr); + } + bar(){ + return `${this.name} used ${this.weapons} and reduced ${villain} opponents healthPoints by 10`; + } } - Hero.prototype = Object.create(Humanoid.prototype); - Hero.prototype.bar =function(villain){ - return `${this.name} used ${this.weapons} and reduced ${villain} opponents healthPoints by 10`; - } + /* From 584493faa40c6475e8c504067c9a4611d389f866 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 15:35:37 -0600 Subject: [PATCH 5/7] JS project IV complete --- assignments/lambda-classes.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 78629c375..b2a54dbba 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -21,6 +21,9 @@ class Instructor extends Person{ demo(subject){ console.log(`Today we are learning about ${subject}`); } + grade(student, subject){ + console.log(`${student.name} receives a perfect score on ${subject}`) + } } class Student extends Instructor{ @@ -28,16 +31,16 @@ class Student extends Instructor{ super(attr); this.previousBackground = attr.previousBackground; this.className = attr.className; - this.favSubject = attr.favSubject; + this.favSubjects = attr.favSubjects; } listSubjects(){ - console.log(`My favorite subjects are ${this.favSubject}`); + console.log(`${this.name}'s favorite subjects are ${this.favSubjects}`); } PRAssignment(subject){ console.log(`${this.name} has submitted a PR for ${subject}`); } sprintChallange(subject){ - console.log(`${this.name} has begun the sprint challenge on ${this.subject}`); + console.log(`${this.name} has begun the sprint challenge on ${subject}`); } } @@ -45,11 +48,11 @@ class Student extends Instructor{ class ProjectManager extends Instructor{ constructor(attr){ super(attr); - this.grandClassName = attr.grandClassName; + this.gradClassName = attr.gradClassName; this.favInstructor = attr.favInstructor; } - standup(slack){ - console.log(`${this.name} announces to ${channel}, @channel standy times!`); + standup(channel){ + console.log(`${this.name} announces to ${channel}, standy times!`); } debugCode(student, subject){ console.log(`${this.name} debugs ${student.name}'s code on ${subject}`); @@ -75,7 +78,7 @@ const student = new Student({ catchPhrase: '', previousBackground: 'Exercise Physiology', className: 'WEB23', - favSubject: 'CSS' + favSubjects: ['HTML',' CSS',' JavaScript'] }) const pm = new ProjectManager({ @@ -85,14 +88,16 @@ const pm = new ProjectManager({ specialty: 'redux', favLanguage: 'Python', catchPhrase: 'Im so proud of you guys', - grandClassName: 'CS1', + gradClassName: 'CS1', favInstructor: 'Britt' }) -console.log(instructor.demo()); + +console.log(instructor.demo('JavaScript')); +console.log(instructor.grade(student, 'JavaScript')); console.log(student.listSubjects()); -console.log(student.PRAssignment()); -console.log(student.sprintChallange()); -console.log(pm.standup()); -console.log(pm.debugCode()); \ No newline at end of file +console.log(student.PRAssignment('JavaScript IV')); +console.log(student.sprintChallange('JavaScript Fundamentals')); +console.log(pm.standup('@channel')); +console.log(pm.debugCode(student, 'Repl.it Challenge')); \ No newline at end of file From e6f1b0b64138edf3f19ccea723009b3126934dc9 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 15:46:28 -0600 Subject: [PATCH 6/7] JS project IV complete 2 --- assignments/lambda-classes.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index b2a54dbba..6e7720341 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -7,7 +7,7 @@ class Person{ this.location = attr.location; } speak(){ - console.log(`Hello, my name is ${this.name}, I am from ${this.location}`); + return (`Hello, my name is ${this.name}, I am from ${this.location}`); } } @@ -19,10 +19,10 @@ class Instructor extends Person{ this.catchPhrase = attr.catchPhrase; } demo(subject){ - console.log(`Today we are learning about ${subject}`); + return (`Today we are learning about ${subject}`); } grade(student, subject){ - console.log(`${student.name} receives a perfect score on ${subject}`) + return (`${student.name} receives a perfect score on ${subject}`) } } @@ -34,13 +34,13 @@ class Student extends Instructor{ this.favSubjects = attr.favSubjects; } listSubjects(){ - console.log(`${this.name}'s favorite subjects are ${this.favSubjects}`); + return (`${this.name}'s favorite subjects are ${this.favSubjects}`); } PRAssignment(subject){ - console.log(`${this.name} has submitted a PR for ${subject}`); + return (`${this.name} has submitted a PR for ${subject}`); } sprintChallange(subject){ - console.log(`${this.name} has begun the sprint challenge on ${subject}`); + return (`${this.name} has begun the sprint challenge on ${subject}`); } } @@ -52,10 +52,10 @@ class ProjectManager extends Instructor{ this.favInstructor = attr.favInstructor; } standup(channel){ - console.log(`${this.name} announces to ${channel}, standy times!`); + return(`${this.name} announces to ${channel}, standy times!`); } debugCode(student, subject){ - console.log(`${this.name} debugs ${student.name}'s code on ${subject}`); + return(`${this.name} debugs ${student.name}'s code on ${subject}`); } } From d88a9a92d772faac67c3ca626b86bc02ae059eb5 Mon Sep 17 00:00:00 2001 From: dominique maack Date: Thu, 22 Aug 2019 20:12:53 -0600 Subject: [PATCH 7/7] JS project IV complete 3 --- assignments/lambda-classes.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 6e7720341..9c8686afa 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -34,7 +34,11 @@ class Student extends Instructor{ this.favSubjects = attr.favSubjects; } listSubjects(){ - return (`${this.name}'s favorite subjects are ${this.favSubjects}`); + let string = ''; + for (let i=0; i < this.favSubjects.length; i++){ + string += this.favSubjects[i] + ' '; + } + return `${this.name}'s favorite subjects are ${string}`; } PRAssignment(subject){ return (`${this.name} has submitted a PR for ${subject}`); @@ -78,7 +82,7 @@ const student = new Student({ catchPhrase: '', previousBackground: 'Exercise Physiology', className: 'WEB23', - favSubjects: ['HTML',' CSS',' JavaScript'] + favSubjects: ['Human Physiology','Biomechanics','Computer Science'] }) const pm = new ProjectManager({ @@ -96,8 +100,14 @@ const pm = new ProjectManager({ console.log(instructor.demo('JavaScript')); console.log(instructor.grade(student, 'JavaScript')); + + + console.log(student.listSubjects()); console.log(student.PRAssignment('JavaScript IV')); console.log(student.sprintChallange('JavaScript Fundamentals')); + + + console.log(pm.standup('@channel')); console.log(pm.debugCode(student, 'Repl.it Challenge')); \ No newline at end of file