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,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.
* [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**
* [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.
* [X] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Description

Expand Down
84 changes: 83 additions & 1 deletion assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,83 @@
// CODE here for your Lambda Classes
class Person {
constructor(attr) {
this.name = attr.name;
this.location = attr.location;
this.age = attr.age;
this.gender = attr.gender;
}

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

class Instructor extends Person {
constructor(attr) {
super(attr);
this.specialty = attr.specialty;
this.favLangiage = attr.favLangiage;
this.catchPhrase = attr.catchPhrase;
}

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

// Modified for stretch
grade(student, subject) {
let score = Math.random() * 100 // A number between 0 and 100
console.log(`${student.name} receives a score of ${score} on ${subject}`);

//Avreage of this score and students original score
let newGrade = (score + student.grade) / 2;
student.grade = newGrade;
}
}

class Student extends Person {
constructor(attr) {
super(attr);
this.previousBackground = attr.previousBackground;
this.className = attr.className;
this.favSubjects = attr.favSubjects;
this.grade = Math.random() * 100;
}

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

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

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

graduate (){
if(this.grade >= 70){
console.log(`Congratulations! ${this.name} has graduated lambda school with a grade of ${this.grade}!`);
} else {
console.log(`${this.name} was unable to graduate because their grade was too low. Keep grinding!`);
}
}
}

class ProjectManager extends Instructor {
constructor(attr) {
super(attr);
this.gradClassName = attr.gradClassName;
this.favInstructor = attr.favInstructor;
}

standUp(channel) {
console.log(`${this.name} announces to ${channel}, @channel time for a standy boi!`);
}

debugsCode(student, subject) {
console.log(`${this.name} debugs ${student.name}'s code on ${subject}`);
}
}
251 changes: 251 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,254 @@ 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.

*/

// function GameObject(attr) {
// this.createdAt = attr.createdAt;
// this.name = attr.name;
// this.dimensions = attr.dimensions;
// }

// GameObject.prototype.destroy = function() {
// return `${this.name} was removed from the game`;
// };

class GameObject {
constructor(atrributes) {
this.createdAt = atrributes.createdAt;
this.name = atrributes.name;
this.dimensions = atrributes.dimensions;
}

destroy() {
return `${this.name} was removed from the game`;
}
}

// function CharacterStats(attr) {
// GameObject.call(this, attr);
// this.healthPoints = attr.healthPoints;
// }

// CharacterStats.prototype = Object.create(GameObject.prototype);

// /* updated for stretch */
// CharacterStats.prototype.takeDamage = function(damage) {
// this.healthPoints -= damage;
// if (this.healthPoints <= 0) {
// return `Critical damage! ` + this.destroy();
// } else
// return `${this.name} took damage. Health remaining: ${this.healthPoints}`;
// };

class CharacterStats extends GameObject {
constructor(attributes) {
super(attributes);
this.healthPoints = attributes.healthPoints;
}

takeDamage(amt) {
this.healthPoints -= amt;
return this.healthPoints <= 0
? `Critical damage! ` + this.destroy()
: `${this.name} took damage. Health remaining: ${this.healthPoints}`;
}
}

// function Humanoid(attr) {
// CharacterStats.call(this, attr);
// this.team = attr.team;
// this.weapons = attr.weapons;
// this.language = attr.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}`;
}
}

// 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(5)); // 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!

/****************
* The takeDamage() method has been updated above for optimal implementation of this stretch
*
*/

// function Villain(attr) {
// Humanoid.call(this, attr);
// //this.super();

// this.spitPotionAt = function(target) {
// console.log(`${this.name} spit potion at ${target.name}!`);
// return target.takeDamage(5);
// };
// this.castSpellOn = function(target) {
// console.log(`${this.name} cast a spell on ${target.name}!`);
// //regenerates health when this attack is used
// this.healthPoints += 1;
// return target.takeDamage(3);
// };
// }

// Villain.prototype = Object.create(Humanoid.prototype);

class Villain extends Humanoid {
constructor(attributes) {
super(attributes);
}

spitPotionAt(target) {
console.log(`${this.name} spit potion at ${target.name}!`);
return target.takeDamage(5);
}

castSpellOn(target) {
console.log(`${this.name} cast a spell on ${target.name}!`);
//regenerates health when this attack is used
this.healthPoints += 1;
return target.takeDamage(3);
}
}

// function Hero(attr) {
// Humanoid.call(this, attr);
// //this.super();

// this.swordStab = function(target) {
// console.log(`${this.name} stabbed ${target.name} with a sword!`);
// return target.takeDamage(6);
// };
// this.airstrike = function(target) {
// console.log(`${this.name} launched an airstrike on ${target.name}!`);
// this.healthPoints += 2;
// return target.takeDamage(2);
// };
// }

// Hero.prototype = Object.create(Humanoid.prototype);

class Hero extends Humanoid {
constructor(attributes) {
super(attributes);
}

swordStab(target) {
console.log(`${this.name} stabbed ${target.name} with a sword!`);
return target.takeDamage(6);
}

airstrike(target) {
console.log(`${this.name} launched an airstrike on ${target.name}!`);
this.healthPoints += 2;
return target.takeDamage(2);
}
}

const houdini = new Villain({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1
},
healthPoints: 15,
name: "Houdini",
team: "Leeches",
weapons: ["Annoying words"],
language: "Basic Tongue"
});

const momoney = new Hero({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 2
},
healthPoints: 18,
name: "Mo Money",
team: "Seeds",
weapons: ["JavaScript code"],
language: "Full-Stack Tongue"
});

console.log(houdini.spitPotionAt(momoney));
console.log(momoney.airstrike(houdini));
console.log(houdini.castSpellOn(momoney));
console.log(momoney.swordStab(houdini));
console.log(houdini.castSpellOn(momoney));
console.log(momoney.swordStab(houdini));
console.log(houdini.spitPotionAt(momoney));
console.log(momoney.airstrike(houdini));
console.log(houdini.castSpellOn(momoney));
console.log(momoney.airstrike(houdini));