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

class Person {
constructor(props) {
this.name = props.name;
this.age = props.age;
this.location = props.location;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`
}
}
class Instructor extends Person {
constructor(personProps) {
super(personProps);
this.specialty = personProps.specialty;
this.favLanguage = personProps.favLanguage;
this.catchPhrase = personProps.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(studentProps) {
super(studentProps);
this.previousBackground = studentProps.previousBackground;
this.className = studentProps.className;
this.favSubjects = studentProps.favSubjects;
this.grade = studentProps.grade;
}
listsSubjects() {
return `${this.favSubjects}`
}
PRAssignment(student, subject) {
return `${student} has submitted a PR for ${subject}`
}
sprintChallenge(student, subject) {
return `${student} has begun sprint challenge on ${subject}`
}
graduate() {
if(this.grade < 70) {
return "fail"
} else {
return "pass"
}
}
}
class ProjectManager extends Instructor {
constructor(PMProps) {
super(PMProps);
this.gradClassName = PMProps.gradClassName;
this.favInstructor = PMProps.favInstructor;
}
standUp(name, channel) {
return `${name} announces to ${channel}, @channel standy times!​​​​​`
}
debugsCode(name, subject) {
return `${name} debugs ${student.name}'s code on ${subject}`
}
grade(name) {
// min = Math.ceil(min);
// max = Math.floor(max);
return `${name} recives a score of` + " " + Math.floor(Math.random() * 100);
}
}

const dan = new Instructor({
name: 'Dan',
location: 'Denver',
age: 37,
favLanguage: 'JavaScript, Python',
specialty: 'Front-end',
catchPhrase: `If you can do the thing, you can get paid to do the thing`
});

const anthony = new Student({
name: 'Anthony',
location: 'Brooklyn',
age: 29,
className: "Web21",
favSubjects: "Javascript",
});

const aj = new ProjectManager({
name: "AJ",
gradClassName: "Web18",
favInstructor: "Josh",
});
console.log(aj.grade(anthony.name, 1));
console.log(anthony.graduate());
console.log(dan.demo("Object Oriented Programming"));
console.log(dan.catchPhrase);
console.log(dan.grade(anthony.name, "JavaScript-IV"));
console.log(anthony.speak(anthony, location));
console.log(aj.standUp(aj.name, "web21_anthony"));
console.log(anthony.sprintChallenge(anthony.name, "Javascript-IV"))
128 changes: 128 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,131 @@ 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.

*/


// 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 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 CharacterStats(attributes) {
// GameObject.call(this, attributes)
// this.healthPoints = attributes.healthPoints;
// }

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

class CharacterStats extends GameObject {
constructor(charAttrs) {
super(charAttrs);
this.healthPoints = charAttrs.healthPoints;
}
takeDamage() {
return `${this.name} took damage.`
}
}

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

// Humanoid.prototype = Object.create(CharacterStats.prototype)
// Humanoid.prototype.greet = function() {
// return `${this.name} offers a greeting in ${this.language}`
// }
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}`
}
}


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.