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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ 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.
* [X] 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] 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.**

Expand Down
109 changes: 109 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
// CODE here for your Lambda Classes
class Person {
constructor(attributes) {
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
}
speak() {
return `Hello my name is Fred, I am from Bedrock where ${this.name} and ${this.location} are the object's own props`
}
}
class Instructor extends Person {
constructor(attributes) {
super(attributes);
this.specialty = attributes.specialty;
this.favLanguage = attributes.favLanguage;
this.catchPhrase = attributes.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student} receives a perfect score on ${subject}`);
}
instructorGrade() {
return Math.floor(Math.random() * 100 + 1);
}
}
class Student extends Person {
constructor(attributes) {
super(attributes);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
}
listsSubjects() {
console.log(`${this.favSubjects}`);
}
PRAssignment(subject) {
console.log(`${this.name} has submitted a PR for ${subject}`);
}
sprintChallenge(subject) {
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}
grade() {
return Math.floor(Math.random() * 100 + 1);
}
graduate() {
if(jay.grade() - dan.instructorGrade() > 30) {
console.log();
return `${this.name} has graduated!`;
} else {
return `${this.name} failed!`
}
}
}

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

const dan = new Instructor({
name: "Dan",
specialty: "Web-Development",
favLanguage: "JavaScript",
catchPhrase: "Don't forget the homies"
});

const devin = new Person({
name: "Devin",
age: 28,
location: "California"
});

const jay = new Student({
name: "Jay",
previousBackground: "Construction Worker",
className: "WEB20",
favInstructor: "Josh Knell",
favSubjects: ['Math', 'Science', 'Social Studies', 'Programming']
});

const adam = new ProjectManager({
name: "Adam",
gradClassName: "WEB19",
favInstructor: "Josh Knell"
});


console.log(devin.speak());
console.log(dan.demo('parameters'));
console.log(dan.grade('Mike', 'JS classes'));
console.log(dan.instructorGrade());
console.log(jay.listsSubjects());
console.log(jay.PRAssignment('PRA'));
console.log(jay.sprintChallenge('JavaScript'));
console.log(jay.grade());
console.log(jay.graduate());
console.log(adam.standUp('group channel'));
console.log(adam.debugsCode('Mike', 'LESS'));
125 changes: 125 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,128 @@ 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.`
*/

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
*/

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 '<object name> offers a greeting in object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

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!