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
113 changes: 113 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,114 @@
// CODE here for your Lambda Classes
class Person {
constructor(personAttr) {
this.name = personAttr.name;
this.age = personAttr.age;
this.location = personAttr.location;
this.gender = personAttr.gender;
}
introduction() {
return `Hello my name is ${this.name}, I am from ${this.location}`;
}
}
class Instructor extends Person {
constructor(instructorAttr) {
super(instructorAttr);
this.specialty = instructorAttr.specialty;
this.favLanguage = instructorAttr.favLanguage;
this.catchPhrase = instructorAttr.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(studentAttr) {
super(studentAttr);
this.previousBackground = studentAttr.previousBackground;
this.className = studentAttr.className;
this.favSubjects = studentAttr.favSubjects;
}

listsSubjects() {
this.favSubjects.forEach((value) => {
console.log(value);
})
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`;
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}`;
}
}

class ProjectManager extends Instructor {
constructor(PMAttr) {
super(PMAttr);
this.gradClassName = PMAttr.gradClassName;
this.favInstructor = PMAttr.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}`;
}
}

//------ Objects ------\\

//------ Instructors
const Cam = new Instructor({
name: 'Cam Pope',
location: 'West Coast',
age: 30,
gender: 'Male',
specialty: 'Drinking water',
favLanguage: 'Javascript',
catchPhrase: `Why isn't this working?`,
});
// console.log(Cam);
// console.log(Cam.introduction());
// console.log(Cam.demo('JavaScript'));

//------ Students
const Carlos = new Student({
name: 'Carlos Sanchez',
location: 'Florida',
age: 21,
gender: 'Male',
previousBackground: `Went to a vocational school for programming`,
className: 'WebPT5',
favSubjects: ['Math', 'Gym', 'Lunch']
});
// console.log(Carlos);
// console.log(Carlos.introduction());
// Carlos.listsSubjects();
// console.log(Carlos.PRAssignment('JavaScript'));
// console.log(Carlos.sprintChallenge('JavaScript'));
// console.log(Cam.grade(Carlos, 'Nothing'));

//------ PMs
const Joseph = new ProjectManager({
name: 'Joseph Stanfield',
location: 'Not sure',
age: 30,
gender: 'Male',
specialty: 'Drawing',
favLanguage: 'Python',
catchPhrase: 'It works on my machine.',
gradClassName: 'WEBPT5',
favInstructor: 'Cam Pope'
});

// console.log(Joseph);
// console.log(Joseph.introduction());
// console.log(Joseph.demo('Python'));
// console.log(Joseph.grade(Carlos, 'Python'));
// console.log(Joseph.standUp('webpt5'));
// console.log(Joseph.debugsCode(Carlos, 'Python'));
122 changes: 121 additions & 1 deletion assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*

Prototype Refactor

Expand All @@ -7,3 +7,123 @@ 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.

*/

//------ ES5 classes
/*
function GameObject(character) {
this.createdAt = character.createdAt;
this.name = character.name;
this.dimensions = character.dimensions;
}
GameObject.prototype.destroy = function () {
return `${this.name} was removed from the game.`;
};
*/
/*
function CharacterStats(stats) {
GameObject.call(this, stats);
this.healthPoints = stats.healthPoints;
}
CharacterStats.prototype = Object.create(GameObject.prototype);
CharacterStats.prototype.takeDamage = function () {
return `${this.name} took damage`;
};
*/
/*
function Humanoid(humanoidOpts) {
CharacterStats.call(this, humanoidOpts);
this.team = humanoidOpts.team;
this.weapons = humanoidOpts.weapons;
this.language = humanoidOpts.language;
}
Humanoid.prototype = Object.create(CharacterStats.prototype);
Humanoid.prototype.greet = function () {
return `${this.name} offers a greeting in ${this.language}`;
};
*/
//------ ES6 classes
class GameObject {
constructor(character) {
this.createdAt = character.createdAt
this.name = character.name
this.dimensions = character.dimensions
}
destroy() {
return `${this.name} was removed from the game.`;
}
}
class CharacterStats extends GameObject {
constructor(stats) {
super(stats)
this.healthPoints = stats.healthPoints
}
takeDamage() {
return `${this.name} took damage`;
}
}
class Humanoid extends CharacterStats {
constructor(humanoidOpts) {
super(humanoidOpts)
this.team = humanoidOpts.team
this.weapons = humanoidOpts.weapons
this.language = humanoidOpts.language
}
greet() {
return `${this.name} offers a greeting in ${this.language}`;
}
}

//------ Objects
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()
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.