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

class Instructor extends Person{
constructor(attrs){
super(attrs);
this.specialty = attrs.specialty;
this.favLanguage = attrs.favLanguage;
this.catchPhrase = attrs.catchPhrase;
}
demo(subject){
return `Today we are learning about ${subject}`;
}
grade(student,subject){
return `${student} receives a perfect score on ${subject}`;
}
}

class Student extends Person{
constructor(attrs){
super(attrs);
this.previousBackground = attrs.previousBackground;
this.className = attrs.className;
this.favSubjects = attrs.favSubjects;
}
listSubjects(){
return `My favorite subjects are ${this.favSubjects[0]} and ${this.favSubjects[1]}!`;
}
PRAssignment(subject){
return `${this.name} has submitted a PR for ${subject}`;
}
}

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

const Student1 = new Student({
name: "Jason",
age: 24,
location: "Texas",
previousBackground: "none",
className: "Full Stack Web Development",
favSubjects: ["Javascript", "React"]

})

const Student2 = new Student({
name: "Billy Bob",
age: 60,
location: "Oklahoma",
previousBackground: "Computer Science",
className: "Javascript",
favSubjects: ["CSS", "HTML"]

})

const Ins1 = new Instructor({
name : "Robert",
age : 45,
location: "Hawaii",
specialty: "Arrays",
favLanguage: "Javascript",
catchPhrase: "Boom Baby"
});

const Ins2 = new Instructor({
name : "Delilah",
age : 27,
location: "Nebraska",
specialty: "Objects",
favLanguage: "React",
catchPhrase: "Mind blown!"
});

const PM1 = new ProjectManager({
name : "Jessica",
age : 47,
location: "Mars",
specialty: "debugging",
favLanguage: "C+",
catchPhrase: "Let's get it!",
gradClassName: "WEB6",
favInstructor: "Billy Bean"
});

const PM2 = new ProjectManager({
name : "Randy Baby",
age : 31,
location: "Venus",
specialty: "Not sure",
favLanguage: "Python",
catchPhrase: "Another one!",
gradClassName: "CS4",
favInstructor: "Marsha Marsha Marsha"
})

console.log(Ins1.age);
console.log(Ins1.demo("JS arrays!"));
console.log(Ins2.name);
console.log(Ins2.grade(Student1.name, "Objects!"));
console.log(Student1.listSubjects());
console.log(Student1.PRAssignment("react"));
console.log(Student2.listSubjects());
console.log(Student2.PRAssignment("Javascript II"));
console.log(PM1.standUp("Web 7"));
console.log(PM1.debugsCode(Student2.name, "Javascript"));
console.log(PM2.standUp("CS 8"));
console.log(PM2.debugsCode(Student1.name, "React"));
131 changes: 131 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,134 @@ 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.

*/

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

// function GameObject(attributes){
// this.createdAt = attributes.createdAt;
// this.name = attributes.name;
// this.dimensions = attributes.dimensions;
// }

// GameObject.prototype.destroy = function(){
// 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!`;
}
}

// function CharacterStats(charattrs){
// GameObject.call(this, charattrs);
// this.healthPoints = charattrs.healthPoints;
// }


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

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

// function Humanoid(humanattrs){
// CharacterStats.call(this, humanattrs);
// this.team = humanattrs.team;
// this.weapons = humanattrs.weapons;
// this.language = humanattrs.language;
// }


// Humanoid.prototype = Object.create(GameObject.prototype);
// Humanoid.prototype = Object.create(CharacterStats.prototype);
// Humanoid.prototype.greet = function(){
// return `${this.name} offers a greeting in ${this.language}}`;
// }
// CharacterStats.prototype.takeDamage = function(){
// return `${this.name} took damage!`;
// }


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.