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
116 changes: 116 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,117 @@
// CODE here for your Lambda Classes

class Person{
constructor(attributes){
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
this.gender = attributes.gender;
}
speak(){
return `Hello my name is ${this.name}, I am from ${this.location}.`;
}
}

class Instructor extends Person{
constructor(attributes){
super(attributes);
this.specialty = attributes.specialty;
this.favLanguage = attributes.favLanguage;
this.catchPhrase = attributes.catchPhrase;
}
demo(subject){
return `Today we are learning about ${subject}.`;
}
grade(student, subject){
return `${student.name} receives a perfect score on ${subject}.`
}
gradeAssignment(student){
student.grade += (Math.random() * (50 - (-50)) + (-50));
return `${student.name}'s grade is ${student.grade}.`;
}
}

class Student extends Person{
constructor(attributes){
super(attributes);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
this.grade = attributes.grade;
}
listSubjects(){
return this.favSubjects;
}
PRAssignment(subject){
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject){
return `${this.name} has begun spring challenge on ${subject}.`;
}
graduate(instructor){
if(this.grade >= 70){
return `${this.name} has graduated.`;
}
else{
return instructor.gradeAssignment(this);
}
}
}

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

const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});

const wilma = new Student({
name: 'Wilma',
location: 'Couchrock',
previousBackground: 'waitress',
className: 'CS132',
favSubjects: ['HTML', 'CSS', 'JavaScript'],
grade: 50
});

const pebbles = new ProjectManager({
name: 'Pebbles',
location: 'Bedstone',
gradClass: 'CS1',
favInstructor: 'Sean'
});

console.log(fred);
console.log(wilma);
console.log(pebbles);
console.log(fred.speak());
console.log(wilma.speak());
console.log(pebbles.speak());
console.log(fred.demo("Redux"));
console.log(fred.grade(wilma, "JavaScript"));
console.log(wilma.listSubjects());
console.log(wilma.PRAssignment("Python"));
console.log(wilma.sprintChallenge("Elm"));
console.log(pebbles.demo("HTML"));
console.log(pebbles.grade(wilma, "CSS"));
console.log(pebbles.standUp("CS132"));
console.log(pebbles.debugsCode(wilma, "JavaScript"));
console.log(fred.gradeAssignment(wilma));
console.log(wilma.graduate(fred));
57 changes: 28 additions & 29 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +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) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
class GameObject{
constructor(options){
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}
destroy(){
return `${this.name} 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}.`;
}
}

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(),
dimensions: {
Expand Down Expand Up @@ -87,4 +86,4 @@ 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.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.