Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ This challenge focuses on classes in JavaScript using the new `class` keyword.

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [x] Create a forked copy of this project.
* [x] Add your project manager as collaborator on Github.
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [x] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Description
Expand Down
100 changes: 100 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
// CODE here for your Lambda Classes

class Person {
constructor(persAttrs) {
this.name = persAttrs.name;
this.age = persAttrs.age;
this.location = persAttrs.location;
}
speak() {
return `Hello, my name is ${this.name}, I am from ${this.location}.`;
}
}

class Instructor extends Person {
constructor(instAttrs) {
super(instAttrs);
this.specialty = instAttrs.specialty;
this.favLanguage = instAttrs.favLanguage;
this.catchPhrase = instAttrs.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}`;
}
grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}`;
}
}

class Student extends Person {
constructor(stuAttrs) {
super(stuAttrs);
this.previousBackground = stuAttrs.previousBackground;
this.className = stuAttrs.className;
this.favSubjects = stuAttrs.favSubjects;
}
listsSubjects() {
return `${this.favSubjects}`;
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}.`;
}
}

class TeamLead extends Instructor {
constructor(tlAttrs) {
super(tlAttrs);
this.gradClassName = tlAttrs.gradClassName;
this.favInstructor = tlAttrs.favInstructor;
}
standUp(channel) {
return `${this.name} announces to ${channel}, @Channel standy times!`;
}
debugsCode(student, subject) {
return `${this.name} debugs ${student.name}'s code on ${subject}`;
}
}

let teacher = new Instructor({
name: 'Mario',
location: 'NY',
age: '42',
specialty: 'Plumbing',
favLanguage: 'JavaScript',
catchPhrase: "It's-a me! Mario!",
})

let apprentice = new Student({
name: 'Luigi',
location: 'NY',
age: '38',
previousBackground: 'Little Brother',
className: 'WEBPT11',
favSubjects: ['HTML', 'CSS', 'JavaScript'],
})

let mentor = new TeamLead({
name: 'Toad',
location: 'Mushroom Kingdom',
age: '100',
specialty: 'Being annoying',
favLanguage: 'PHP',
catchPhrase: "Thank you Mario, but our princess is in another castle!",
gradClassName: 'WEBPT 3',
favInstructor: 'Mario',
})

console.log(teacher.speak());
console.log(apprentice.speak());
console.log(mentor.speak());
console.log(teacher.demo('JavaScript'));
console.log(teacher.grade(apprentice, 'Advanced CSS'));
console.log(apprentice.listsSubjects());
console.log(apprentice.PRAssignment('HTML'));
console.log(apprentice.sprintChallenge('JavaScript'));
console.log(mentor.standUp('#webpt11'));
console.log(mentor.debugsCode(apprentice, 'JavaScript'));
console.log(mentor.demo('PHP'));
console.log(mentor.grade(apprentice, 'JavaScript'));
162 changes: 162 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,165 @@ 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.

*/

/*
=== 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(attributes) {
this.createdAt = attributes.createdAt;
this.name = attributes.name;
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.name = attributes.name;
this.dimensions = attributes.dimensions;
}
destroy() {
return `${this.name} was removed from the game.`;
}
}

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

/*
function CharacterStats(attributes) {
this.healthPoints = attributes.healthPoints;
GameObject.call(this, attributes);
}
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;
}
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 '<object name> offers a greeting in <object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/
/*
function Humanoid(attributes) {
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
CharacterStats.call(this, attributes);
}
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.