Skip to content
144 changes: 144 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,145 @@
// CODE here for your Lambda Classes

/////////////////////////////
// First build the classes //
/////////////////////////////

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

speak() {
console.log(`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) {
console.log(`Today we are learning about ${subject}`);
}

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

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

listsSubjects() {
console.log(this.favSubjects.toString());
}

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

sprintChallenge(subject) {
console.log(`${this.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.name} announces to ${channel}, @channel standy times!`);
}

debugsCode(student, subject) {
console.log(`${this.name} debugs ${student.name}'s code on ${subject}`);
}
}

////////////////////////////
// Now build some people! //
////////////////////////////

const danLevy = new Instructor({
name: 'Dan Levy',
location: 'Denver?',
age: 32,
favLanguage: 'JavaScript',
specialty: 'FSW',
catchPhrase: `Don't listen to Rosie`
});

const joshKnell = new Instructor({
name: 'Josh Knell',
location: 'Georgia?',
age: 31,
favLanguage: 'Ruby',
specialty: 'banjo',
catchPhrase: `You got this!`
});

const avni = new Student({
name: 'Avni Patel Thompson',
location: 'Seattle',
age: 28,
className: 'WEB21',
previousBackground:`Founder & CEO of Poppy`,
favSubjects: ['Node.js', 'Summer Hackers', 'Array methods'],
});

const virginia = new Student({
name: 'Virginia Thayer',
location: 'Seattle',
age: 36,
previousBackground: 'User Operations at Stripe',
className: 'WEB21',
favSubjects: ['LESS', 'JavaScript', 'Pseudo-classical inheritance']
});

const joshuaSmoot = new ProjectManager({
name: 'Joshua Smoot',
age: 26,
location: 'Charleston',
favInstructor: 'Josh Knell',
gradClassName: 'WEB17'
});

const mary = new ProjectManager({
name: 'Mary',
age: 24,
gradClassName: 'WEB18',
favInstructor: 'Josh Knell',
location: 'New York',
specialty: 'Express and Node.js',
favLanguage: 'Python',
catchPhrase: "That looks AWESOME",
});

console.log(joshuaSmoot.gradClassName);
console.log(mary.favInstructor);
console.log(mary.favLanguage);
console.log(danLevy.catchPhrase);
joshKnell.demo('JavaScript');
danLevy.grade(virginia, 'Class Constructors');
joshuaSmoot.standUp('#web21_Smoot');
avni.speak();
virginia.PRAssignment('JavaScript IV');
joshKnell.speak();
virginia.sprintChallenge('LESS');
mary.grade(avni, 'HTML');
avni.listsSubjects();

117 changes: 117 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,120 @@ 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.

*/



////////////////
// REFACTORED //
////////////////

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

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

}

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

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

}

class Humanoid extends CharacterStats {
constructor(humAttrs) {
super(humAttrs);
this.team = humAttrs.team;
this.weapons = humAttrs.weapons;
this.language = humAttrs.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`
}
}

///////////////////
///// TESTING /////
// DOES IT WORK? //
///////////////////

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!