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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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.
* [] 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
* [ ] Your project manager will count the project as complete by merging the branch back into master.
* [X] 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
* [] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Description

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

class Person {
constructor(personAttributes) {
this.name = personAttributes.name;
this.age = personAttributes.age;
this.location = personAttributes.location;
}

speak(){
console.log(`Hello my is name ${this.name} I am from ${this.location}`);
}
}

class Instructor extends Person {
constructor(instrutorAttributes) {
super(instrutorAttributes);
this.speciality = instrutorAttributes.speciality;
this.favLanguage = instrutorAttributes.favLanguage;
this.catchPhrase = instrutorAttributes.catchPhrase;
}

demo(subject) {

console.log(`Today we are learning about ${subject}`);

}

grade(student, subject) {
console.log(`${student.name} recieves a perfect score on ${subject}`);
}
}

class student extends Person {
constructor(studentAttributes) {
super(studentAttributes);
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
}

listSubjects() {
for(i = 0; i < this.favSubjects.length; i++)
{
console.log(this.favSubjects[i]);
}
}

PRAassignment(subject) {
console.log(`${student.name} has submitted a PR for ${subject}`);
}

sprintChallenge(subject) {
console.log(`${student.name} has begun sprint challenge on ${subject}`);
}
}

class projectManager extends Instructor {
constructor(pmAttributes) {
super(pmAttributes);
this.gradClassName = pmAttributes.gradClassName;
this.favInstructor = pmAttributes.favInstructor;
}

standUP(channel) {
console.log(`${this.gradClassName} announces to ${channel} @channel standby times`);
}

debugsCode() {
console.log(`${this.gradClassName} debugs ${student.name}'s code on ${subject}`);
}
}
228 changes: 224 additions & 4 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,229 @@
/*
/*
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.

Prototype Refactor
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.

1. Copy and paste your code or the solution from yesterday
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.`
*/

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(characterAttributes) {
super(characterAttributes);
this.healthPoints = characterAttributes.healthPoints;
}

takeDamage() {
return(`${this.name} took damage`);
}

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.
}

/*
=== 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(humanoidAttributes) {

super(humanoidAttributes);
this.team = humanoidAttributes.team;
this.weapons = humanoidAttributes.weapons;
this.language = humanoidAttributes.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!

class Villian extends Humanoid {

constructor(villainAttributes){

super(villainAttributes);
this.laugh = villainAttributes.laugh;
this.stature = villainAttributes.stature;

}

decrementVillianPoints() {
this.healthPoints = this.healthPoints - 1;
console.log(`The villain has taken 1 dmg! This is his current HP ${this.healthPoints}`);
}

}


class Hero extends Humanoid{

constructor(heroAttributes) {
super(heroAttributes);
this.nobility = heroAttributes.nobility;
this.aura = heroAttributes.aura;
}

decrementHeroPoints() {
this.healthPoints = this.healthPoints - 5;
console.log(`The villain has taken 1 dmg! This is his current HP ${this.healthPoints}`);
}
}

const Guts = new Hero({

createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
healthPoints: 10,
name: 'Black Swordsman',
team: 'Forest Kingdom',
weapons: [
'Sword',
'Cannon',
],
language: 'Elvish',

});

const Griffith = new Villian({

createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
healthPoints: 10000,
name: 'Femto',
team: 'Demon Army',
weapons: [
'Bow',
'Dagger',
],
language: 'All',

});

Guts.decrementHeroPoints();

for(let i = 0; i < 10; i++)
Griffith.decrementVillianPoints()

Guts.decrementHeroPoints();