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
123 changes: 123 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,124 @@
// CODE here for your Lambda Classes
class Person{
constructor(attrs){
this.name = attrs.name;
this.age = attrs.age;
this.location = attrs.location;
}
speak(){
console.log(`Hello my name is Fred, I am from Bedrock where ${this.name} and ${this.location}`);
}
}
class Instructor extends Person{
constructor(attrs){
super(attrs);
this.specialty = attrs.specialty;
this.favLanguage = attrs.favLanguage;
this.catchPhrase = attrs.catchPhrase;

}
demo(subject){
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject){
console.log(`${student} recieves 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;
}
listsSubjects(){

for(let i = 0; i < this.favSubjects.length; i++)
console.log(this.favSubjects[i]);
}
PRAssignment(subject){
console.log(`${this.name} has submitted a PR for ${subject}`)
}
sprintChallenge(subject){
console.log(`${this.name} has begun sprint challenge on ${subject}`)
}
}
class ProjectManagers extends Instructor{
constructor(attrs){
super(attrs);
this.gradClassName = attrs.gradClassName;
this.favInstructor = attrs.favInstructor;
}
standUp(channel){
console.log(`${this.name} announces to ${channel}, @channel standy times!`);
}
debugsCode(student, subject){
console.log(`${this.name} debugs ${student}'s code on ${subject}`);
}
}

const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});
const paul = new Instructor({
name: 'Paul',
location: 'Los Angeles',
age: 56,
favLanguage: 'Python',
specialty: 'Back-end',
catchPhrase: `Your all gonna fail!`
});
const mike = new Student({
name: 'Mike',
location: 'Bedrock',
age: 20,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: 'I can do it',
previousBackground: 'Bartender',
className: 'webpt12',
favSubjects: ['HTML','CSS','JavaScript']

});
const sally = new Student({
name: 'Sally',
location: 'Boston',
age: 20,
favLanguage: 'Python',
specialty: 'Full-Stack',
catchPhrase: `Go for goal`,
previousBackground: 'Skateboarder',
className: 'webpt11',
favSubjects: ['Python','CSS', 'C++']
});
const frank = new ProjectManagers({
name: 'Frank',
location: 'Boston',
age: 35,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Whatever it takes`
});
const diane = new ProjectManagers({
name: 'Diane',
location: 'Bedrock',
age: 23,
favLanguage: 'Python',
specialty: 'Full-Stack',
catchPhrase: `Let's Zoom!`
});

console.log(frank.standUp('webpt11'));
console.log(diane.debugsCode('sally', 'computer-science'));
console.log(sally.listsSubjects());
console.log(sally.className);
console.log(mike.sprintChallenge('Data-Structure'));
console.log(paul.demo('DOM manipulation'));
console.log(paul.age);
console.log(paul.grade('sally', 'Python'));
153 changes: 153 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,156 @@ 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(attrs){
this.createdAt = attrs.createdAt;
this.name = attrs.name;
this.dimensions = attrs.dimensions;
}

// function GameObject(attrs) {
// this.createdAt = attrs.createdAt;
// this.name = attrs.name;
// this.dimensions = attrs.dimensions;
// }
destroy(attrs) {
console.log(`${this.name} was removed from the game`);
}
}
// GameObject.prototype.destroy = function (remove) {
// console.log(`${this.name} was removed from the game`);
// }
/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
class CharacterStats extends GameObject {
constructor(healthPoints){
super(healthPoints);
this.damageAmount = healthPoints.damageAmount;
}

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

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

takeDamage(){
console.log(`${this.name} took damage`);
return `${this.name} took damage`;
}
}
// CharacterStats.prototype.takeDamage = function () {
// console.log(`${this.name} took damage`);
// 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
*/
class Humanoid extends CharacterStats{
constructor(human){
super(human);
//CharacterStats.call(this, human);
this.team = human.team;
this.weapons = human.weapons;
this.language = human.language;
}

// function Humanoid(human) {
// CharacterStats.call(this, human);
// this.team = human.team;
// this.weapons = human.weapons;
// this.language = human.language;
// }
//Humanoid.prototype = Object.create(CharacterStats.prototype);
greet() {
console.log(`${this.name} says hello in ${this.language}`);
return `${this.name} says hello in ${this.language}`;
}
}
// Humanoid.prototype.greet = function (greeting) {
// console.log(`${this.name} says hello in ${this.language}`);
// return `${this.name} says hello 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.