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
181 changes: 181 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,182 @@
// CODE here for your Lambda Classes
class Person {
constructor(attributes){
this.name = attributes.name,
this.age = attributes.age;
this.location = attributes.location;
}
// Method go here!
speak(){
console.log(`Hello my name is ${this.name} and I am from ${this.location}.`);
}
}// Person

class Instructor extends Person{
constructor(instructorAttributes){
super(instructorAttributes);
this.specialty = instructorAttributes.specialty;
this.favLanguage = instructorAttributes.favLanguage;
this.catchPhrase= instructorAttributes.catchPhrase;
}
//write methods here!
demo(subject){
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject){
console.log(`${student.name} receives a perfect score on ${subject}`);
}
}//Instructor

class Student extends Person{
constructor(studentAttributes){
super(studentAttributes);
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
}
//methods here
listsSubjects(){
console.log(`${this.favSubjects}`);
}

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

sprintChallenge(subject){
console.log(`${this.name} has begun sprint challenge on ${subject}.`);
}
}//Student

class ProjectManagers extends Instructor{
constructor(pmAttributes){
super(pmAttributes);
this.gradClassName = pmAttributes.gradClassName;
this.favInstructor = pmAttributes.favInstructor;
}
//methods here
standUp(channel){
console.log(`${this.name} announces to ${channel}, @channel standy times!`);
}
debugsCode(student, subject){
console.log(`${this.name} debugs ${student.name}'s code on ${subject}.`);
}
}//ProjectManagers


//PERSONS
const kevin = new Person({
name: 'Kevin',
age: 40,
location: 'Scraton'
})

const creed = new Person({
name: 'Creed',
age: 60,
location: 'no where'
})


//INSTRUCTORS
const Michael = new Instructor({
name: 'Michael Scott',
age: 50,
location: 'Dunder Mifflin',
specialty: 'C++',
favLanguage: 'Python',
catchPhrase: 'thats what she said!'
})

const David = new Instructor({
name: 'David Wallace',
age: 52,
location: 'New york',
specialty: 'C#',
favLanguage: 'JavaScript',
catchPhrase: 'have michael call me please.'
})

//STUDENTS
const jim = new Student({
name: 'Jim',
age: 28,
location: 'scraton',
specialty: 'HTML',
favLanguage: 'Pyton',
catchPhrase: "Just gives you smirk",
previousBackground: 'College basketball player',
className: 'WEB22',
favSubjects: ['CSS', 'React', 'JavaScript']
})

const pam = new Student({
name: 'Pam',
age: 27,
location: 'scraton',
specialty: 'UI/UX',
favLanguage: 'CSS',
catchPhrase: "I can design anything!",
previousBackground: 'receptionist at Dunder Mifflin',
className: 'WEB22',
favSubjects: ['Html', 'UI', 'CSS']
})

//PMs
const Andy = new ProjectManagers({
name: 'Andy',
age: 38,
location: 'Cornell',
specialty: 'Java',
favLanguage: 'CSS',
catchPhrase: "I went to cornell!",
previousBackground: 'acapella singer',
className: 'WEB23',
favSubjects: ['React', 'SQL', 'JavaScript'],
gradClassName: 'WEB21',
favInstructor: 'Michael'
})

const Dwight = new ProjectManagers({
name: 'Dwight',
age: 50,
location: 'Schrute Farms',
specialty: 'python',
favLanguage: 'Javascript',
catchPhrase: "Question?",
previousBackground: 'Beat Farmer',
className: 'WEB22',
favSubjects: ['CSS', 'HTML', 'LESS'],
gradClassName: 'WEB20',
favInstructor: 'Michael'
})

kevin.speak();
creed.speak();

Michael.speak();
David.speak();
Michael.demo('CSS');
Michael.grade(jim, 'JavaScript');
David.demo('React');
David.grade(pam, 'CSS');

jim.speak();
pam.speak();
jim.listsSubjects();
pam.listsSubjects();
jim.PRAssignment('CSS');
pam.PRAssignment('HTML');
jim.sprintChallenge('SQL');
pam.sprintChallenge('CSS');

Andy.speak();
Dwight.speak();
Andy.demo('JavaScrtipt');
Dwight.grade(jim, 'CSS');
Andy.demo('HTML');
Dwight.grade(pam, 'C#');
Andy.standUp('Cornel grads');
Dwight.standUp('Schrute farms');
Andy.debugsCode(jim, 'HTML');
Dwight.debugsCode(pam, "CSS");
185 changes: 182 additions & 3 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,188 @@
/*

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

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

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

class GameObject {
constructor(gameObj) {
this.createdAt = gameObj.createdAt;
this.name = gameObj.name;
this.dimensions = gameObj.dimensions;
}

destroy() {
return `${this.name} was removed from the game.`;
}
}

// function GameObject(gameObj) {
// this.createdAt = gameObj.createdAt;
// this.name = gameObj.name;
// this.dimensions = gameObj.dimensions;
// }

// GameObject.prototype.destroy = function() {
// return `${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(stats) {
super(stats);
this.healthPoints = stats.healthPoints;
}

takeDamage() {
return `${this.name} took damage.`;
}
}


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

class Humanoid extends CharacterStats {
constructor(human) {
super(human);
this.team = human.team;
this.weapons = human.weapons;
this.language = human.language;
}

greet() {
return `${this.name} offers a greeting in ${this.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);

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


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