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

class Instructor extends Person{
constructor(instructAttributes){
super(instructAttributes);
this.newSpecialty = instructAttributes.specialty;
this.newFavLanguage = instructAttributes.favLanguage;
this.newCatchPhrase = instructAttributes.catchPhrase;
this.newSubject = instructAttributes.subject;
}
demo(subject){
return `Today we are learning about ${subject}`;
}
grade(student, subject){
return `${student.newName} recieves a perfect score on ${subject}`;
}
}

class Student extends Person{
constructor(studentAttributes){
super(studentAttributes);
this.newPreviousBackground = studentAttributes.previousBackground;
this.newClassName = studentAttributes.className;
this.newFavSubjects = studentAttributes.favSubjects;
}
listsSubjects(){
return `${this.newFavSubjects}`
}
PRAssignment(subject){
return `${this.newName} has submitted a PR for ${subject}`;
}
sprintChallenge(subject){
return `${this.newName} has begun sprint challenge on ${subject}`;
}
}

class ProjectManager extends Instructor{
constructor(pmAttributes){
super(pmAttributes);
this.newGradClassName = pmAttributes.gradClassName;
this.newFavInstructor = pmAttributes.favInstructor;
}
standUp(channel){
return `${this.newName} announces to ${channel}, @channel standy times!`;
}
debugsCode(student, subject){
return `${this.newName} debugs ${student.newName}'s code on ${subject}`;
}
}

const john = new Instructor({
name: 'John',
location: 'New York',
age: 28,
favLanguage: 'JavaScript',
specialty: 'Full-stack',
catchPhrase: 'Have a great day'

});

const hannah = new Instructor({
name: 'Hannah',
location: 'Chicago',
age: 28,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: 'Helllooo'

});

const april = new Student({
name: 'April',
location: 'California',
age: 25,
previousBackground: 'sales',
className: 'CS132',
favSubjects: [
'HTML',
' CSS',
' Javascript',
],
});

const zack = new Student({
name: 'Zack',
location: 'Holland',
age: 22,
previousBackground: 'medicine',
className: 'CS132',
favSubjects: [
' HTML',
' React',
' Node',
],
});
const laura = new ProjectManager({
name: 'Laura',
location: 'Atlanta',
age: 32,
favLanguage: 'React',
specialty: 'Back-end',
catchPhrase: 'Good luck',
gradClassName: 'CS1',
favInstructor: 'John'
});

const jackson = new ProjectManager({
name: 'Jackson',
location: 'Florida',
age: 40,
favLanguage: 'React',
specialty: 'Full-stack',
catchPhrase: 'Hey there',
gradClassName: 'CS2',
favInstructor: 'Hannah'
});
console.log(john.speak());
console.log(laura.speak());
console.log(april.speak());
console.log(hannah.speak());
console.log(zack.speak());
console.log(john.demo("CSS"));
console.log(hannah.demo("CSS"));
console.log(john.grade(april, "Javascript"));
console.log(april.listsSubjects());
console.log(zack.listsSubjects());
console.log(april.PRAssignment("Node"));
console.log(april.sprintChallenge("Advanced Javascript"));
console.log(laura.standUp("web23"));
console.log(jackson.standUp("IOS2"));
console.log(laura.debugsCode(april, "Computer Science"))
114 changes: 114 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,117 @@ 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.

*/
//=== GameObject ===
class GameObject{
constructor(attributes){
this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.dimensions;
//(These represent the character's size in the video game)
}
destroy(){
return `${this.name} was removed from the game.`;
}
// /* prototype method that returns: `${this.name} was removed from the game.`*/
}
//=== CharacterStats ===
class CharacterStats extends GameObject{
constructor(statsAttributes){
super(statsAttributes);
this.healthPoints = statsAttributes.healthPoints;
}
takeDamage(){
return `${this.name} took damage.`
}
}
// 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.) ===
class Humanoid extends CharacterStats{
constructor(hAttributes){
super(hAttributes);
this.team = hAttributes.team;
this.weapons = hAttributes.weapons;
this.language = hAttributes.language;
}
greet(){
return `${this.name} offers a greeting in ${this.language}`
}
}
// 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.