diff --git a/README.md b/README.md index 09f6b65fe..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 @@ -51,15 +50,14 @@ const fred = new Instructor({ }); ``` -#### Person + + #### Student 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 diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..aeb2df16f 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,137 @@ // 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} receives a perfect score on ${subject}.` + }; +}; + +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 diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..161ca1719 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -1,9 +1,205 @@ /* - 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. +*/ + +/* + === 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.`; + } +}; + +/* + === 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 extends GameObject { + constructor(attributes) { + super(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 extends CharacterStats{ + constructor(attributes) { + super(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