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
201 changes: 201 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,202 @@
// CODE here for your Lambda Classes
class Person {
constructor (personAttrs) {
this.name = personAttrs.name;
this.age = personAttrs.age;
this.location = personAttrs.location;
this.gender = personAttrs.gender;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`;
}
}

class Instructor extends Person {
constructor(instructorAttrs) {
super(instructorAttrs);
this.specialty = instructorAttrs.specialty;
this.favLanguage = instructorAttrs.favLanguage;
this.catchPhrase = instructorAttrs.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(studentAttrs) {
super(studentAttrs);
this.previousBackground = studentAttrs.previousBackground;
this.className = studentAttrs.className;
this.favSubjects = studentAttrs.favSubjects;
this.grade = studentAttrs.grade;
}
listsSubjects() {
this.favSubjects.forEach(function(subject) {
console.log(subject);
});
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}.`;
}
graduate() {
if (this.grade > 70) {
return `${this.name} is ready to graduate!`
}
return `${this.name} needs to increase their score before graduating!`
}
}

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

//=======INSTRUCTORS

const adam = new Instructor({
name: 'Adam',
age: 31,
location: 'Liverpool',
gender: 'male',
specialty: 'Back-end',
favLanguage: 'Python',
catchPhrase: 'Don\'t panic!'
});

const gustavo = new Instructor({
name: 'Gustavo',
age: 29,
location: 'Bogota',
gender: 'male',
specialty: 'Front-end',
favLanguage: 'Javascript',
catchPhrase: 'Just one more thing...'
});

const dominika = new Instructor({
name: 'Dominika',
age: 36,
location: 'Krakow',
gender: 'female',
specialty: 'Back-end',
favLanguage: 'Ruby',
catchPhrase: 'Yada, yada, yada!'
});

//=======STUDENTS

const luca = new Student({
name: 'Luca',
age: 26,
location: 'Melbourne',
gender: 'male',
previousBackground: 'Graphic Designer',
className: 'FSW17',
favSubjects: [
'HTML',
'Javascript',
],
grade: 75,
});

const elena = new Student({
name: 'Elena',
age: 29,
location: 'Bucharest',
gender: 'female',
previousBackground: 'Student',
className: 'FSW16',
favSubjects: [
'React',
'Javascript',
],
grade: 84,
});

const eloise = new Student({
name: 'Eloise',
age: 31,
location: 'Lyon',
gender: 'female',
previousBackground: 'Business Analyst',
className: 'FSW17',
favSubjects: [
'Python',
'Ruby',
],
grade: 62,
});

//======PROJECT MANAGERS

const randy = new ProjectManager({
name: 'Randy',
age: 40,
location: 'New York',
gender: 'male',
specialty: 'Front-end',
favLanguage: 'Javascript',
catchPhrase: 'You\'re fired!',
gradClassName: 'CS13',
favInstructor: 'Gustavo',
});

const skylar = new ProjectManager({
name: 'Skylar',
age: 25,
location: 'Seattle',
gender: 'female',
specialty: 'Back-end',
favLanguage: 'Python',
catchPhrase: 'Lovely jubbly!',
gradClassName: 'CS14',
favInstructor: 'Dominika'
});

const mortimer = new ProjectManager({
name: 'Mortimer',
age: 65,
location: 'Pleasantville',
gender: 'male',
specialty: 'Back-end',
favLanguage: 'Ruby',
catchPhrase: 'I pity the fool!',
gradClassName: 'CS4',
favInstructor: 'Adam',
});

console.log(adam.speak());
console.log(gustavo.specialty);
console.log(dominika.favLanguage);
console.log(gustavo.catchPhrase);
console.log(adam.demo('Redux'));
console.log(dominika.grade('Eloise', 'CSS'));
console.log(elena.previousBackground);
console.log(elena.className);
console.log(luca.favSubjects);
console.log(eloise.PRAssignment('Javascript'));
console.log(luca.sprintChallenge('React'));
console.log(mortimer.speak());
console.log(mortimer.gradClassName);
console.log(skylar.favInstructor);
console.log(randy.standUp('Randy\'s group'));
console.log(skylar.debugsCode(luca, 'Python'));
elena.listsSubjects();
console.log(elena.graduate());
console.log(eloise.graduate());
127 changes: 127 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,130 @@ 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.

*/
// ===== Instructions were purposefully left in to better visualize the refactoring.
/*
=== GameObject ===
* createdAt
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
*/

class GameObject {
constructor(gameObjectAttrs) {
this.createdAt = gameObjectAttrs.createdAt;
this.dimensions = gameObjectAttrs.dimensions;
this.name = gameObjectAttrs.name;
}
destroy() {
return `${this.name} was removed from the game.`;
}
}

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

class CharacterStats extends GameObject {
constructor(charAttributes) {
super(charAttributes);
this.healthPoints = charAttributes.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
*/

class Humanoid extends CharacterStats {
constructor(humanoidAttrs) {
super(humanoidAttrs);
this.team = humanoidAttrs.team;
this.weapons = humanoidAttrs.weapons;
this.language = humanoidAttrs.language;
}
greet() {
return `${this.name} offers 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 your 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.