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

class Instructor extends Person {
constructor(instructorStats) {
super(instructorStats);
this.specialty = instructorStats.specialty;
this.favLanguage = instructorStats.favLanguage;
this.catchPhrase = instructorStats.catchPhrase;
}
demo(subject){
return `Today we are learning about ${subject}`;
}
grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}`;
}
grade(student) {
return `${student.name} recieves a score of ${student.grade - (Math.floor(Math.random() * student.grade) + 1)}`
}
}




class Student extends Person {
constructor(studentStats) {
super(studentStats);
this.previousBackground = studentStats.previousBackground;
this.className = studentStats.className;
this.favSubjects = studentStats.favSubjects;
this.grade = studentStats.grade;
}
listsSubjects() {
return this.favSubjects;
}
PRAssignment(subject) {
return `${this.name} has submitted a PR ${subject}`;
}
sprintChallenge(subject) {
return `${this.name} has submitted a PR for {subject}`;
}
graduate() {
if (this.grade > 70) {
return 'You have graduated!';
} else {
return 'Failure to achieve graduation! Please try again!';
}
}
}

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

const lily = new Person({
name: 'Lily',
location: 'Atlanta',
age: 23,
gender: 'female',
favLanguage: 'Java',
specialty: 'Back-end',
catchPhrase: `All about the back-end`
});

const george = new Instructor({
name: 'George',
location: 'Salt Lake City',
age: 47,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Born and raised in Utah`
});

const mark = new Student({
name: 'Mark',
location: 'San Diego',
age: 21,
gender: 'male',
favLanguage: 'Python',
specialty: 'Back-end',
catchPhrase: `I hate Javascript`,
previousBackground: `Hack Reactor`,
className: 'HR14',
favSubjects: ['Math', 'Economics', 'Politics'],
grade: 80
});

const stephanie = new ProjectManager({
name: 'Stephanie',
location: 'Phoenix',
age: 29,
gender: 'female',
favLanguage: 'Go',
specialty: 'Full-stack',
catchPhrase: `Learning programming since I was 14`,
gradClassName: 'HR10',
favInstructor: 'Mike'
});

console.log(lily.name);
console.log(lily.speak());
console.log(george.favLanguage);
console.log(george.demo('math'));
console.log(george.grade(george, 'math'));
console.log(mark.className);
console.log(mark.favSubjects);
console.log(mark.PRAssignment('math'));
console.log(mark.sprintChallenge());
console.log(stephanie.gradClassName);
console.log(stephanie.standUp('random'));
console.log(stephanie.debugsCode('mark', 'economics'));
console.log(mark.graduate());
console.log(mark.grade)
console.log(george.grade(mark));
// Stretch
s


50 changes: 25 additions & 25 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
// Today 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(options) {
class GameObject {
constructor(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}
destroy() {
return `Object was removed from the game.`;
}
}

GameObject.prototype.destroy = function() {
return `Object was removed from the game.`;
};

function CharacterStats(characterStatsOptions) {
GameObject.call(this, characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.name = characterStatsOptions.name;
class CharacterStats extends GameObject {
constructor(characterStatsOptions) {
super(characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.name = characterStatsOptions.name;
}
takeDamage() {
return `${this.name} took damage.`;
}
}

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

CharacterStats.prototype.takeDamage = function() {
return `${this.name} took damage.`;
};

function Humanoid(humanoidOptions) {
CharacterStats.call(this, humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
class Humanoid extends CharacterStats {
constructor(humanoidOptions) {
super(humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Nice job, Randy.

}
}

Humanoid.prototype = Object.create(CharacterStats.prototype);

Humanoid.prototype.greet = function() {
return `${this.name} offers a greeting in ${this.language}.`;
};

const mage = new Humanoid({
createdAt: new Date(),
Expand Down