From e9c0d81201623446d9399fc421e808decccd9067 Mon Sep 17 00:00:00 2001 From: Brandi Apetsi Date: Sat, 26 Jan 2019 17:54:35 -0500 Subject: [PATCH 1/5] initial commit --- assignments/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/index.html b/assignments/index.html index 2fc751cde..eeee23da1 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -5,7 +5,7 @@ - JS IV + JS IV From b4ac731db38a850e413a97d9114e9c946073a2be Mon Sep 17 00:00:00 2001 From: Brandi Apetsi Date: Tue, 29 Jan 2019 17:46:36 -0500 Subject: [PATCH 2/5] work on prototype conversion --- assignments/prototype-refactor.js | 175 ++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..b0634efca 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,178 @@ 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. */ +/* + 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 + * dimensions (These represent the character's size in the video game) + * destroy() // prototype method -> returns the string: 'Object was removed from the game.' +*/ + +// function GameObject(attributes) { +// this.createdAt = attributes.createdAt; +// this.dimensions = attributes.dimensions; + +// } + +// GameObject.prototype.destroy = function(){ +// return `${this.name} was removed from the game.`; +// } + +class GameObject { + constructor(attributes) { + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; + } + + destroy() { + return `${this.name} was removed from the game.` + } +} + +/* +=== CharacterStats === +* healthPoints +* name +* takeDamage() // prototype method -> returns the string ' took damage.' +* should inherit destroy() from GameObject's prototype +*/ +// function CharacterStats(attributes) { +// GameObject.call(this, attributes); +// this.healthPoints = attributes.healthPoints; +// this.name = attributes.name; +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); + +// CharacterStats.prototype.takeDamage = function(){ +// return `${this.name} took damage.`; +// } + +class CharacterStats { + constructor(attributes) { + this.healthPoints = attributes.healthPoints; + this.name = attributes.name; + } + + takeDamage() { + 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(attributes) { +// CharacterStats.call(this, attributes); +// this.team = attributes.team; +// this.weapons = attributes.weapons; +// this.language = attributes.language; +// } + +// Humanoid.prototype = Object.create(CharacterStats.prototype); + +// Humanoid.prototype.greet = function(){ +// return `${this.name} offers a greeting in ${this.language}.`; +// } + +class Humanoid { + constructor(attributes) { + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + + greet() { + return `${this.name} offers a greeting in ${this.language}.`; + } +} + +/* +* 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', +}); + +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. + + +// 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 2146a4418df5bc9badf12c77efbebe93b0a8bff7 Mon Sep 17 00:00:00 2001 From: Brandi Apetsi Date: Tue, 29 Jan 2019 20:06:41 -0500 Subject: [PATCH 3/5] finished prototype refactor --- assignments/prototype-refactor.js | 135 +++++++++++++++++------------- 1 file changed, 78 insertions(+), 57 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index b0634efca..161ca1719 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,29 +1,44 @@ /* - 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. - */ + /* - 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. + === GameObject === + * createdAt + * dimensions (These represent the character's size in the video game) + * destroy() // prototype method -> returns the string: 'Object was removed from the game.' +*/ +// function GameObject(attributes) { +// this.createdAt = attributes.createdAt; +// this.dimensions = attributes.dimensions; + +// } + +// GameObject.prototype.destroy = function(){ +// return `${this.name} was removed from the game.`; +// } - In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. +class GameObject { + constructor(attributes) { + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; + } - 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: -*/ + destroy() { + return `${this.name} was removed from the game.`; + } +}; /* === GameObject === * createdAt * dimensions (These represent the character's size in the video game) * destroy() // prototype method -> returns the string: 'Object was removed from the game.' -*/ - +* // function GameObject(attributes) { // this.createdAt = attributes.createdAt; // this.dimensions = attributes.dimensions; @@ -41,7 +56,7 @@ class GameObject { } destroy() { - return `${this.name} was removed from the game.` + return `${this.name} was removed from the game.`; } } @@ -64,8 +79,10 @@ class GameObject { // return `${this.name} took damage.`; // } -class CharacterStats { +class CharacterStats extends GameObject { constructor(attributes) { + super(attributes); + this.healthPoints = attributes.healthPoints; this.name = attributes.name; } @@ -97,8 +114,10 @@ class CharacterStats { // return `${this.name} offers a greeting in ${this.language}.`; // } -class Humanoid { +class Humanoid extends CharacterStats{ constructor(attributes) { + super(attributes); + this.team = attributes.team; this.weapons = attributes.weapons; this.language = attributes.language; @@ -116,54 +135,56 @@ class Humanoid { */ // 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 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 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', + 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 From 513ff4e2a4a3faf884d44edb876036e9668ab646 Mon Sep 17 00:00:00 2001 From: Brandi Apetsi Date: Tue, 29 Jan 2019 20:47:18 -0500 Subject: [PATCH 4/5] work on lambda-classes --- README.md | 4 ++-- assignments/lambda-classes.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09f6b65fe..143d78581 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,12 @@ const fred = new Instructor({ }); ``` -#### Person + #### Instructor diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..1e51aa5f7 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,32 @@ // CODE here for your Lambda Classes + +class Person { + constructor(perAttributes) { + this.name = perAttributes.name; + this.age = perAttributes.age; + this.location = perAttributes.location; + this.gender = perAttributes.gender; + } + + speak() { + return `Hello, my name is ${this.name}. I am from ${this.location}.`; + } +}; + +class Instructor extends Person { + constructor(instAttributes) { + super(instAttributes); + + this.specialty = instAttributes.specialty; + this.favLanguage = instAttributes.favLanguage; + this.catchPhrase = instAttributes.catchPhrase; + } + + demo(subject) { + return `Today, we are learning about ${subject}.` + }; + + grade(student, subject) { + return `${student.name} receives a perfect score on ${subject}.` + }; +} \ No newline at end of file From 9008e3446205113fe6f58b4f63b85acec10c339e Mon Sep 17 00:00:00 2001 From: Brandi Apetsi Date: Wed, 30 Jan 2019 01:21:25 -0500 Subject: [PATCH 5/5] finished lambda-classes --- README.md | 10 ++-- assignments/lambda-classes.js | 109 +++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 143d78581..9bb6dc18e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# JavaScript IV + ## `lambda-classes` - We need a roster of Lambda School personnel. Build it! - * We have a school to build here! This project will get you used to thinking about classes in JavaScript and building them from a brand new data set. * Lambda personnel can be broken down into three different types of `people`. * **Instructors** - extensions of Person @@ -58,8 +57,7 @@ const fred = new Instructor({ * Person receives `speak` as a method. * 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 --> -#### Instructor - + #### Student diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 1e51aa5f7..aeb2df16f 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -27,6 +27,111 @@ class Instructor extends Person { }; grade(student, subject) { - return `${student.name} receives a perfect score on ${subject}.` + return `${student} receives a perfect score on ${subject}.` }; -} \ No newline at end of file +}; + +class Student extends Person { + constructor(stuAttributes) { + super(stuAttributes); + + this.previousBackground = stuAttributes.previousBackground; + this.className = stuAttributes.className; + this.favSubjects = stuAttributes.favSubjects; + } + + listsSubjects() { + return `${this.favSubjects}`; + }; + + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}.`; + }; + + sprintChallenge(subject) { + return `${this.name} has begun spring challenge on ${subject}.`; + }; +} + +class ProjMgr extends Instructor { + constructor(pmAttributes) { + super(pmAttributes); + + this.gradClassName = pmAttributes.gradClassName; + this.favInstructor = pmAttributes.favInstructor; + this.standUp = pmAttributes.standUp; + } + + debugsCode(subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}.` + } +} + +const larry = new Person({ + name: "Larry", + age: 20, + location: "Maryland", + gender: 'male' +}); + +const jerry = new Person({ + name: "Jerry", + age: 50, + location: "Texas", + gender: 'male' +}); + +console.log(larry.speak()); + +const laura = new Instructor({ + name: "Laura", + age: 29, + location: "Montana", + gender: 'female', + specialty: "CSS", + favLanguage: ["jquery", "Node"] + +}); + +const jack = new Instructor({ + name: "Jack", + age: 50, + location: "Canada", + gender: 'male', + specialty: "bootstrap", + favLanguage: ["JS", "HTML"] +}); + +console.log(laura.demo("the DOM")); +console.log(jack.grade(jack.name, "JS IV")) + + +const lane = new Student({ + name: "Lane", + age: 88, + location: "Missouri", + gender: 'male', + specialty: "LESS", + favLanguage: ["JS", " Python", " Golang"], + previousBackground: "construction", + className: "CS1", + favSubjects: ["Python", " Golang"] +}); + +const joy = new Student({ + name: "Joy", + age: 90, + location: "Toronto", + gender: 'female', + specialty: "redux", + favLanguage: ["Ruby", " Haskel", " Go"], + previousBackground: "nail art", + className: "CS15", + favSubjects: ["HTML", "SASS"] +}); + +console.log(lane.listsSubjects()); +console.log(lane.PRAssignment("React I")); +console.log(lane.sprintChallenge("Ruby")); + +console.log(joy.sprintChallenge("Redux II")); \ No newline at end of file