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
160 changes: 160 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,161 @@
// CODE here for your Lambda Classes
// Base Class
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}.`;
}
}
// Child Class
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}.`;
}
}
// Child Class
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);
}
}
}

// Child Class
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: 'D-Rock',
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: 'CS211',
favInstructor: 'Frankenstein'
});

const bambam = new ProjectManager({
name: 'BamBam',
location: 'Toadrock',
gradClass: 'CS191',
favInstructor: 'Gazoo'
});


const betty = new Student({
name: 'Betty',
location: 'D-Rock',
previousBackground: 'waitress',
className: 'CS132',
favSubjects: ['HTML', 'CSS', 'JavaScript'],
grade: 60
});

const barney = new Student({
name: 'Barney',
location: 'D-Rock',
previousBackground: 'Disco Dancer',
className: 'CS139',
favSubjects: ['HTML', 'CSS', 'JavaScript'],
grade: 50
});

const gazoo = new Student({
name: 'Gazoo',
location: 'Mars',
previousBackground: 'Disc Jockey',
className: 'Pluto - 3.14',
favSubjects: ['ReduxL', 'CSS', 'JavaScript'],
grade: 550
});








console.log(fred);
console.log(wilma);
console.log(pebbles);
console.log(fred.speak());
console.log(betty.speak());
console.log(barney.speak());
console.log(fred.demo("Redux"));
console.log(bambam.grade(wilma, "JavaScript"));
console.log(betty.listSubjects());
console.log(gazoo.PRAssignment("Python"));
console.log(wilma.sprintChallenge("Elm"));
console.log(bambam.demo("HTML"));
console.log(pebbles.grade(wilma, "CSS"));
console.log(pebbles.standUp("CS132"));
console.log(bambam.debugsCode(wilma, "JavaScript"));
console.log(fred.gradeAssignment(gazoo));
console.log(wilma.graduate(fred));
104 changes: 103 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,105 @@ 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(features) {
this.createdAt = features.createdAt;
this.name = features.name;
this.dimensions = features.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`;
}
}

CharacterStats.prototype = Object.create(gameObject.prototype)


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

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


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.