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
143 changes: 143 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,144 @@
// 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.favLanquage = attributes.favLanquage;
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}`
}
}

class Student extends Person {
constructor(attributes){
super(attributes);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
}
listsSubject(){ // loops through subjects
this.favSubjects.forEach(subject => {
console.log(subject);
});
}
PRAssigment(subject){
return `${this.name} has submitted a PR for ${subject}`;
}
sprintChallenge(subject){
return `${this.name} has begun sprint challenge on ${subject}`
}
}

class PM extends Instructor{
constructor(attributes){
super(attributes);
this.gradClassName = attributes.gradClassName;
this.favInstructor = attributes.favInstructor;
}
standUp(channel){
return `${this.name} announce to ${channel}, @channel standy time`
}
debugCode(student, subject){
return `${this.name} debugs ${student.name}'s code on ${subject}`
}
}
// Instructors
const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});

const dave = new Instructor({
name: 'Dave Everyman',
location: 'Smalltown, USA',
age: 25,
gender: 'male',
favLanguage: 'Ruby',
specialty: 'Back-end',
catchPhrase: 'I like eggs'
});

//Stundents

const milly = new Student ({
name: 'Milly Somename',
age: 19,
location: 'next to that one place.',
gender: 'female',
previousBackground: 'Geology but did not like rocks.',
className: 'WEBPT26',
favSubjects: ['CSS', 'React', 'Redux']
});

const jackie = new Student ({
name: "Jackie No'Chans",
age: 64,
location: 'Victoria Peak, Hong Kong',
gender: 'male',
previousBackground: 'Stunt Double',
className:'CSS14',
favSubjects: ['RESTful', 'Advanced CSS', 'Authentication']
});

// Project Manangers
const batman = new PM ({
name: 'Batman Ben Suparman',
age: 35,
location: 'South Smallville',
gender: 'non binary',
gradClassName: 'CS2',
favInstructor: 'Fred',
catchPhrase: 'Welcome to flavortown!'
})

const mike = new PM({
name: 'Mike Adams',
age: 24,
location: 'Houston, TX',
gender: 'male',
gradClassName: 'WEBPT 1',
favInstructor: 'Dave',
catchPhrase: 'zzz'

})


//Instructor logs
console.log(fred.demo('JavaScript'));
console.log(dave.grade(milly, 'HTML'));
console.log(dave.speak());
console.log(dave.catchPhrase);

//Student logs
console.log(milly.listsSubject());
console.log(milly.PRAssigment('JSII'));
console.log(jackie.sprintChallenge('Redux'));
console.log(milly.speak());

//Project Manager logs
console.log(batman.standUp('WEBPT4'));
console.log(mike.debugCode(milly, 'JavaScript'));

226 changes: 224 additions & 2 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,228 @@ Prototype Refactor

1. Copy and paste your code or the solution from yesterday

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.dimensions= attributes.dimensions;
// }

*/
// GameObject.prototype.destroy= function(){
// return `${this.name} was removed from the game.`;
// }

// /*
// === CharacterStats ===
// * healthPoints
// * name
// * takeDamage() // prototype method -> returns the string '<object name> took damage.'
// * should inherit destroy() from GameObject's prototype
// */
// function CharacterStats (CharacterStatsAttributes){
// GameObject.call(this, CharacterStatsAttributes);
// this.healthPoints =CharacterStatsAttributes.healthPoints;
// this.name =CharacterStatsAttributes.name;
// }

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

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



// /*
// === Humanoid (Having an appearance or character resembling that of a human.) ===
// * team
// * weapons
// * language
// * greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
// * should inherit destroy() from GameObject through CharacterStats
// * should inherit takeDamage() from CharacterStats
// */
// function Humanoid(HumanoidAttributes){
// CharacterStats.call(this, HumanoidAttributes);
// this.team = HumanoidAttributes.team;
// this.weapons =HumanoidAttributes.weapons;
// this.language = HumanoidAttributes.language;
// }


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


// Humanoid.prototype.greet = function () {
// return `${this.name} offers a greeting in ${this.language}`
// }


// /*
// * Inheritance chain: GameObject -> CharacterStats -> Humanoid
// * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
// * Instances of CharacterStats should have all of the same properties as GameObject.
// */

// // Test you work by un-commenting these 3 objects and the list of console logs below:


// 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.



// 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.dimensions= attributes.dimensions;
}
destroy () {
return `${this.name} was removed from the game.`;
}
}


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

}

class Humanoid extends CharacterStats {
constructor(attributes) {
super(attributes)
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.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.