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
186 changes: 186 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,187 @@
// CODE here for your Lambda Classes
/*#### Person

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

class Person {
constructor(PersonProperty) {
this.name = PersonProperty.name;
this.age = PersonProperty.age;
this.location = PersonProperty.location;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`;
}
}

/*#### Instructor

* 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 Instructor extends Person {
constructor(IntructorProperty) {
super(IntructorProperty);
this.specialty = IntructorProperty.specialty;
this.favLanguage = IntructorProperty.favLanguage;
this.catchPhrase = IntructorProperty.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}`;
}
grade(Student, subject) {
return `${Student.name} receives a perfect score on ${subject}`;
}
}

/*### Student

* 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 Student extends Person {
constructor(StudentProperty) {
super(StudentProperty);
this.previousBackground = StudentProperty.previousBackground;
this.className = StudentProperty.className;
this.favSubjects = StudentProperty.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};`;
}
}

/*#### Project Manager

* 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}`
* **/

class PM extends Instructor {
constructor(PMproperty) {
super(PMproperty);
this.gradClassName = PMproperty.gradClassName;
this.favInstructor = PMproperty.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}`;
}
}

/**Tests */

//Person Test
const Mandy = new Person({
name: "Mandy Cruz",
age: 40,
location: "Atlanta, Georgia"
});

console.log(Mandy.name);
console.log(Mandy.age);
console.log(Mandy.location);
console.log(Mandy.speak());

////////////////////////////////////////////////////////
//Student Test

const Chris = new Student({
name: "Chris Baron",
age: 30,
location: "Macon, Georgia",
previousBackground: "Industrial Engineering",
className: "CS105",
favSubjects: "Mathematics and Physics"
});

console.log(Chris.name);
console.log(Chris.age);
console.log(Chris.location);
console.log(Chris.previousBackground);
console.log(Chris.className);
console.log(Chris.favSubjects);
console.log(Chris.listsSubjects());
console.log(Chris.PRAssignment("Flex-Box Project"));
console.log(Chris.sprintChallenge("React"));

//Instructor Test

const Kofi = new Instructor({
name: "Kofi Marcell",
age: 50,
location: "Athens, Georgia",
specialty: "Web Development",
favLanguage: "JavaScript",
catchPhrase: "Live and Let Live"
});

console.log(Kofi.name);
console.log(Kofi.age);
console.log(Kofi.location);
console.log(Kofi.specialty);
console.log(Kofi.favLanguage);
console.log(Kofi.catchPhrase);
console.log(Kofi.demo("Function Declaration"));
console.log(Kofi.grade(Chris, "Functions"));

///////////////////////////////////////////////////////////////////
//Project Manager Test

const Ant = new PM({
name: "Anthony Gibson",
age: 36,
location: "Albany, Georgia",
specialty: "Word Press",
favLanguage: "CSS",
catchPhrase: "Life is a stage",
gradClassName: "CS200",
favInstructor: "Kofi Marcell"
});

console.log(Ant.name);
console.log(Ant.age);
console.log(Ant.location);
console.log(Ant.specialty);
console.log(Ant.favLanguage);
console.log(Ant.catchPhrase);
console.log(Ant.gradClassName);
console.log(Ant.favInstructor);
console.log(Ant.standUp("11222"));
console.log(Ant.debugsCode(Chris, "Functions"));
112 changes: 112 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,115 @@ 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.

*/
/*Class function for GameObject*/

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

// destroy prototype for GameObject
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
*/
/*Class function for CharacterStats*/

class CharacterStats extends GameObject {
constructor(CharProps) {
super(CharProps);
this.healthPoints = CharProps.healthPoints;
}
// takeDamage method for CharacterStats

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 function for Humanoid*/

class Humanoid extends CharacterStats {
constructor(HumanProps) {
super(HumanProps);
this.team = HumanProps.team;
this.weapons = HumanProps.weapons;
this.language = HumanProps.language;
}
//method for Humanoid

greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
}

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