Skip to content

mvp completed #666

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
137 changes: 137 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,138 @@
// CODE here for your Lambda Classes
class Person{
constructor(attr) {
this.name = attr.name;
this.location = attr.location;
this.age = attr.age;
}
speak(){
return `Hello my name is ${this.name}, I am from ${this.location}.`
}
}

class Instructor extends Person{
constructor(attr){
super(attr);
this.specialty = attr.specialty;
this.favLanguage = attr.favLanguage;
this.catchPhrase = attr.catchPhrase;
}
demo(student){
return `Today, we are learning about ${student}.`;
}
grade(student,subject){
return `${student} receives a perfect score on ${subject}.`
}
}

class Student extends Person{
constructor(attr) {
super(attr);
this.previousBackground = attr.previousBackground;
this.className = attr.className;
this.favSubjects = attr.favSubjects;
}
listsSubjects(){

return `These are ${this.name}'s favorite subjects: ${this.favSubjects}.`;
};


PRAssignment(subject){
return `${this.name} has submitted a PR for ${subject}.`
}
sprintChallenge(subject){
return `${this.name} has begun sprint challenge on ${subject}.`
}
}

class ProjectManagers extends Instructor{
constructor(attr){
super(attr);
this.gradClassName = attr.gradClassName;
this.favInstructor = attr.favInstructor;
}
standUp(channel, meetTime){
return `Attention members of ${channel}! Stand up at ${meetTime}.`
}
debugsCode(student, subject){
return `${this.name} debugs ${student}'s code on ${subject}.`
}
}


const allan = new Person({
name: "Allan",
location: "Texas",
age: 56,
});

const ben = new Person({
name: "Ben",
location: "New York",
age: 78
});
const mary = new Instructor({
name: "Mary",
location: "New Jersey",
age: 28,
favLanguage: "Python",
specialty: "Data science",
catchPhrase: "Leave me alone"
});

const linda = new Instructor({
name: "Linda",
location: "New Jersey",
age: 23,
favLanguage: "JavaScript",
specialty: "Backend",
catchPhrase: "Shut up"
});

const zelda = new Student({
name: "Zelda",
location: "Florida",
age: 40,
previousBackground: "IT",
className: "CS101",
favSubjects: ["HTML","CSS","Java","Python"]
});

const john = new Student({
name: "John",
location: "South Carolina",
age: 18,
previousBackground: "IT",
className: "CS204",
favSubjects: ["NodeJS","C#","Java","Python"]
});

const frank = new ProjectManagers({
name: "Frank",
location: "Texas",
age: 36,
gradClassName: "CS2",
favInstructor: "Linda",
channel: "@frank",
meetTime: "2:00PM"
});

const flynn = new ProjectManagers({
name: "Flynn",
location: "New York",
age: 31,
gradClassName: "CS2",
favInstructor: "Mary" ,
channel: "@flynn",
meetTime: "3:00PM"
});

console.log(ben.age);
console.log(allan.location);
console.log(mary.demo());
console.log(linda);
console.log(zelda.listsSubjects());
console.log(frank.standUp("@frankschannel","2:00PM"));
console.log(zelda.PRAssignment("Java"));
console.log(flynn.debugsCode("Ramon","C++"));
168 changes: 166 additions & 2 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,170 @@ 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.

/*
=== 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.`
*/
// function GameObject(attr){
// this.createdAt = attr.createdAt,
// this.name = attr.name,
// this.dimensions = attr.dimensions
// }
// // Prototype Method. Moved out of GameObject function due to memory issues.
// GameObject.prototype.destroy = function(){
// return `${this.name} was removed from the game.`;
// }

class GameObject{
constructor(attr){
this.createdAt = attr.createdAt;
this.name = attr.name;
this.dimensions = attr.dimensions;
}
destroy(){
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
*/
// function CharacterStats(attr){
// this.healthPoints = attr.healthPoints,
// //For inheriting, you are calling this and parameter. Also, you need to create a child contructor.
// // Calling GameObject's attributes
// GameObject.call(this, attr)
// }
// // Creating child constructor.
// // Created child constructor needs to go before all functions.
// CharacterStats.prototype = Object.create(GameObject.prototype);
// CharacterStats.prototype.takeDamage = function(){
// return `${this.name} took damage.`;
// }

class CharacterStats extends GameObject{
constructor(attr){
super(attr);
this.healthPoints = attr.healthPoints;
}
takeDamage(){
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(attr){
// this.team = attr.team,
// this.weapons = attr.weapons,
// this.language = attr.language,
// CharacterStats.call(this, attr)
// }

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

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