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



// * First we need a Person class. This will be our `base-class`
// * Person receives `name` `age` `location` all as props
// * Person receives `speak` as a method.
// * This method logs out a phrase `Hello my name is Fred, I am from Bedrock` where `name` and `location` are the object's own props
// const fred = new Instructor({
// name: 'Fred',
// location: 'Bedrock',
// age: 37,
// favLanguage: 'JavaScript',
// specialty: 'Front-end',
// catchPhrase: `Don't forget the homies`
// });
class Person{
constructor(attributes){
this.name = attributes.name,
this.location=attributes.location,
this.age=attributes.age
}

speak(){
return `Hello my name is ${this.name} , I am from ${this.location}.`;
}
}

class Instructor extends Person{
constructor(instructorAttributes){
super(instructorAttributes);
this.specialty=instructorAttributes.specialty;
this.favLanguage=instructorAttributes.favLanguage;
this.catchPhrase=instructorAttributes.catchPhrase;
}
demo(subject){
return `Today we are learning about ${subject}..`;
}
grade(subject){
return `${this.name} receives a perfect score on ${subject}';`
}
}
// * Now that we have a Person as our base class, we'll build our Instructor class.
// * Instructor uses the same attributes that have been set up by Person
// * Instructor has the following unique props:
// * `specialty` what the Instructor is good at i.e. 'redux'
// * `favLanguage` i.e. 'JavaScript, Python, Elm etc.'
// * `catchPhrase` i.e. `Don't forget the homies`
// * Instructor has the following methods:
// * `demo` receives a `subject` string as an argument and logs out the phrase 'Today we are learning about {subject}' where subject is the param passed in.
// * `grade` receives a `student` object and a `subject` string as arguments and logs out '{student.name} receives a perfect score on {subject}'
class Student extends Person{
constructor(stuentAttributes){
super(stuentAttributes);
this.previousBackground=stuentAttributes.previousBackground;
this.className=stuentAttributes.className;
this.favSubjects=stuentAttributes.favSubjects;
}
listsSubjects(){
return this.favSubjects;
}
PRAssignment(subject){
return `${this.name} has submitted a PR for ${subject}`;
}
sprintChallenge(subject){
return `${this.name} has begun sprint challenge on ${subject}.`
}
}


// * Now we need some students!
// * Student uses the same attributes that have been set up by Person
// * Student has the following unique props:
// * `previousBackground` i.e. what the Student used to do before Lambda School
// * `className` i.e. CS132
// * `favSubjects`. i.e. an array of the student's favorite subjects ['Html', 'CSS', 'JavaScript']
// * Student has the following methods:
// * `listsSubjects` a method that logs out all of the student's favoriteSubjects one by one.
// * `PRAssignment` a method that receives a subject as an argument and logs out that the `student.name has submitted a PR for {subject}`
// * `sprintChallenge` similar to PRAssignment but logs out `student.name has begun sprint challenge on {subject}`

class ProjectManagers extends Instructor{
constructor(pmAttributes){
super(pmAttributes);
this.gradClassName=pmAttributes.gradClassName;
this.favInstructor=pmAttributes.favInstructor;

}
standUp(channel){
return `${this.name} announces to ${channel}, @channel standy times!​​​​​`;
}
debugsCode(student,subject){
return `${this.name} debugs ${student.name}'s code on ${subject}`;
}
}


// * Now that we have instructors and students, we'd be nowhere without our PM's
// * ProjectManagers are extensions of Instructors
// * ProjectManagers have the following unique props:
// * `gradClassName`: i.e. CS1
// * `favInstructor`: i.e. Sean
// * ProjectManagers have the following Methods:
// * `standUp` a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​
// * `debugsCode` a method that takes in a student object and a subject and logs out `{name} debugs {student.name}'s code on {subject}`

const fredrik = new Person({
name: 'Fredrik',
location: 'Bedrock',
age: 34,
});
const Ben = new Person({
name: 'BEN',
location: 'NY',
age: 32,
});
const Bob = new Person({
name: 'Bob',
location: 'Seattle',
age: 47,
});
const jone = new ProjectManagers({
name: 'jone',
location: 'belivue',
age: 36,
favLanguage: 'JavaScript and Redux',
specialty: 'UX',
catchPhrase: `Don't forget coding..`
});
const chris = new Instructor({
name: 'chris',
location: 'California',
age: 28,
favLanguage: 'CSS',
specialty: 'Front-end',
catchPhrase: `Coding is a game..`
});
const merry = new Student({
name: 'merry',
location: 'Canada',
age: 28,
previousBackground:'used to work on a football player assistant.',
className:'CS144',
favSubjects:['Html', 'CSS', 'JavaScript']

});
const maria = new Student({
name: 'maria',
location: 'California',
age: 28,
previousBackground:'used to work on a cafiteria..',
className:'CS132',
favSubjects:['Html', 'CSS', 'JavaScript','C#','Phyton']
});
const Alex= new ProjectManagers({
gradClassName:'CS1',
favInstructor:"jone"
});
const Alm= new ProjectManagers({
gradClassName:'CS3',
favInstructor:"chris"
});

console.log(Ben.speak());
console.log(Bob.speak());
console.log(jone.grade('tom','javascript'));
console.log(chris.speak());
console.log(fredrik.speak());
console.log(Ben.speak());
console.log(Bob.speak());
console.log(jone.standUp('#web22'));
console.log(jone.debugsCode(maria,'javascript'));
console.log(Alex.standUp('#help_web23'));
console.log(Alex.demo("Jscript"));
console.log(Alm.grade('tom','javascript'));
console.log(merry.listsSubjects());
console.log(merry.PRAssignment('UserInterface'));
console.log(merry.sprintChallenge('Userinterface'));
console.log(maria.listsSubjects());
console.log(maria.PRAssignment('UserInterface'));
console.log(maria.sprintChallenge('Userinterface'));

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

*/
/*
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(attributes){
this.createdAt = new Date(),
this.name = attributes.name,
this.dimensions= attributes.dimensions;
//console.log(this);
}
destroy(){
return `${this.name} removed from the game`;
}
}// this closes the parent


/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
class CharacterStats extends GameObject{
constructor(childAttributes){
super(childAttributes), // super replaces parent.call
this.healthPoints=childAttributes.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
*/
class Humanoid extends CharacterStats{
constructor(grandAttributes){
super(grandAttributes),
this.team= grandAttributes.team,
this.weapons=grandAttributes.weapons,
this.language=grandAttributes.language
}
greet(){
return `${this.name} offers a greeting in ${this.newlanguage}`;
}
}

/*
* 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[0]); // 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!