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

class Person {
constructor(attributes){
this.name = attributes.name,
this.age = attributes.age,
this.location = attributes.location
}
speak(){
return `Hello my name is ${this.name}, I am from ${this.location} `;
}
}

class Instructor extends Person {
constructor(insAttribute){
super(insAttribute);
this.specialty = insAttribute.specialty,
this.favLanguage = insAttribute.favLanguage,
this.catchPhrase = insAttribute.catchPhrase
}
demo(subject){
return `Today we are learning about ${subject}` // subject + student inserted into the methods as parameters to be used as arguments when called //
}
grade(student, subject){
return `${student} receives a perfect score on ${subject}`
}
}

class Student extends Person {
constructor(studAttribute){
super(studAttribute);
this.previousBackground = studAttribute.previousBackground,
this.className = studAttribute.className,
this.favSubjects = studAttribute.favSubjects //only students need subjects, other don't inherit from students //
}
listsSubjects() {
return this.favSubjects.forEach(item => console.log(item)); // this.favSubject points to this objects favSubjects//


}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`

}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}`

}

}

class ProjectManager extends Instructor { //grandchild of instructor//
constructor(pmAttribute){
super(pmAttribute); // super and extends always need for class inheritance //
this.gradClassName = pmAttribute.gradClassName,
this.favInstructor = pmAttribute.favInstructor
}
standUp(channel) {
return `${this.name} announces to ${channel} @channel standy times! ` // parameter of 'channel' is put into the method//

}
debugsCode(student, subject) {
return `${this.name} debugs ${student}'s code on ${subject}`

}

}


const Greg = new Student({
name: 'Greg',
location: 'Pahrump',
age: 20,
previousBackground: 'trucker',
className: 'WEB25',
favSubjects: ['CSS', 'HTML', 'JS']
});

const Homer = new Student({
name: 'Homer',
location: 'Springfield',
age: 39,
previousBackground: 'technician',
className: 'UX5',
favSubjects: ['beer', 'tv', 'donuts']
});

const Naruto = new Instructor({
name: 'Naruto',
location: 'Konoha',
age: 20,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Believe it!`
});

const Indiana = new Instructor({
name: 'Indiana',
location: 'Princeton',
age: 33,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `I hate snakes`
});

const Tim = new ProjectManager({
name: 'Tim',
location: 'New York',
age: 29,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: 'I like turtles',
gradClassName: 'WEB25',
favInstructor: 'Indiana'
})

const John = new ProjectManager({
name: 'John',
location: 'Austin',
age: 45,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: 'Where is it?',
gradClassName: 'WEB25',
favInstructor: 'Indiana',

})

console.log(Naruto.grade('Homer', 'BOWLING'));
console.log(Indiana.demo('poop'));

console.log(Tim.debugsCode('Greg', 'JavaScript'));
console.log(John.standUp('HELP'));

console.log(Naruto.speak());

console.log(Homer.sprintChallenge('failure'));
console.log( Homer.PRAssignment('ldfsa'));
Homer.listsSubjects();

184 changes: 184 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,190 @@ 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.

*/

/*
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.

In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.

At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.

Each constructor function has unique properties and methods that are defined in their block comments below:
*/

class GameObject {
constructor(attributes){
this.createdAt = attributes.createdAt,
this.name = attributes.name,
this.dimensions =attributes.dimensions //remember no comma on the last, will give error //
}
destroy() {
return `${this.name} was removed from the game.`; // this is the prototype //
}
}

class CharacterStats extends GameObject {
constructor(charAttributes){
super(charAttributes); // extends + super are what bind child to parent (CharacterStats to GameObject) //
this.healthPoints = charAttributes.healthPoints
}
takeDamage(){
return ` ${this.name} took damage. `; //prototype//
}
}

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


// function GameObject(attributes) {
// this.createdAt = attributes.createdAt, //parent object//
// this.name = attributes.name,
// this.dimensions = attributes.dimensions
// }

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

// function CharacterStats(characterStatsAttributes){
// GameObject.call(this, characterStatsAttributes), //binds to parent //
// this.healthPoints = characterStatsAttributes.healthPoints

// };

// CharacterStats.prototype = Object.create(GameObject.prototype); // new binding used to inherit from parent //


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

// function Humanoid(humanoidAttributes){
// CharacterStats.call(this, humanoidAttributes); // binds to child //
// this.team = humanoidAttributes.team,
// this.weapons = humanoidAttributes.weapons,
// this.language = humanoidAttributes.language

// }

// Humanoid.prototype = Object.create(CharacterStats.prototype); //inherits from child //

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


/*
=== GameObject ===
* createdAt
* name
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${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
*/

/*
=== 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
*/

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


// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
// * Create two new objects, one a villain and one a hero and fight it out with methods!