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
128 changes: 128 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,129 @@
// CODE here for your Lambda Classes
class Person{
constructor(props){
this.name = props.name;
this.age = props.name;
this.location = props.location;
}
greet(){
return `Hello, my name is ${this.name}, I am from ${this.location}`
}
}

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

class Student extends Person{
constructor(props){
super(props);
this.previousBackground = props.previousBackground;
this.className = props.className;
this.favSubjects = props.favSubjects;
};
listsSubjects(){
//copies array (spread operator)
[...this.favSubjects]
};
PRAssignment(subjectStr){
return `${this.name} has submitted a PR for ${subjectStr}.`
};
sprintChallenge(subjectStr){
return `${this.name} has begun the sprint challenge on ${subjectStr}`
}
}

class ProjectManager extends Instructor{
constructor(props){
super(props);
this.gradClassName = props.gradClassName;
this.favInstructor = props.favInstructor;
};
standUp(channel){
return `${this.name} announces to ${channel}, @channel standy times!`
};
debugsCode(studentObj, subjectStr){
return `${this.name} debugs ${studentObj}'s code on ${subjectStr}.`
}
}

const jim = new Instructor({
name:"Jim",
age: "23",
location: "Montana",
specialty: "React",
favLanguage: "Java",
catchPhrase: "Wang Bang Bobble!"
});
const tony = new Instructor({
name:"Tony",
age: "45",
location: "California",
specialty: "Redux",
favLanguage: "JavaScript",
catchPhrase: "Nothin' but a chicken wing on a string."
});
const molly = new Student({
name:"Molly",
age: "19",
location: "Virginia",
previousBackground: "Business Management",
className: "Web254",
favSubjects: ["HTML", "CSS"]
});
const noah = new Student({
name:"Noah",
age: "55",
location: "Maryland",
previousBackground: "Customer Service",
className: "Web868",
favSubjects: ["JavaScript", "Java"]
});
const whis = new ProjectManager({
name:"Whis",
age: "46",
location: "The Moon",
specialty: "Web Design",
favLanguage: "Mark-up",
catchPhrase: "Yak 'em Slack 'em Whack 'em Jack 'em",
gradClassName: "Web937",
favInstructor: "Dirt McGirt"
});
const abe = new ProjectManager({
name:"Abe",
age: "32",
location: "Minnesota",
specialty: "Data Science",
favLanguage: "Mark-down",
catchPhrase: "Uber Stoked!",
gradClassName: "Web000",
favInstructor: "Bob Lund"
});

console.log(abe.greet())
console.log(noah.greet())
console.log(jim.demo("JavaScript"))
console.log(tony.demo("HTML"))
console.log(whis.grade(molly, "JS"))
console.log(jim.grade(noah, "CSS"))
console.log(molly.listsSubjects())
console.log(noah.listsSubjects())
console.log(molly.PRAssignment("LESS"))
console.log(noah.PRAssignment("React"))
console.log(molly.sprintChallenge("Data Science"))
console.log(noah.sprintChallenge("Web Design"))
console.log(whis.standUp("web25"))
console.log(abe.standUp("web25_help"))
console.log(whis.debugsCode(molly.name, "Web Development"))
console.log(abe.debugsCode(noah.name, "Java"))
159 changes: 158 additions & 1 deletion assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,164 @@
Prototype Refactor

1. Copy and paste your code or the solution from yesterday
/*
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.

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.
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.`
*/
// function GameObject(attributes){
// this.createdAt = attributes.createdAt;
// this.name = attributes.name;
// this.dimensions = attributes.dimensions;
// }
// GameObject.prototype.destroy = function(){
// return `${this.name} was removed from the game.`
// }
class GameObject{
constructor(attributes){
this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.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(stats){
// GameObject.call(this, stats);
// this.healthPoints = stats.healthPoints;
// this.damage = stats.damage;
// }
// CharacterStats.prototype = Object.create(GameObject.prototype);
// CharacterStats.prototype.takeDamage = function(){
// return `${this.name} took damage.`
// }
class CharacterStats extends GameObject{
constructor(stats){
super(stats);
this.healthPoints = stats.healthPoints;
this.damage = stats.damage;
}
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(specs){
// CharacterStats.call(this, specs);
// this.team = specs.team;
// this.weapons = specs.weapons;
// this.language = specs.language;
// }
// Humanoid.prototype = Object.create(CharacterStats.prototype);
// Humanoid.prototype.greet = function(){
// return `${this.name} offers a greeting in ${this.language}.`
// }
class Humanoid extends CharacterStats{
constructor(specs){
super(specs);
this.team = specs.team;
this.weapons = specs.weapons;
this.language = specs.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.