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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ const fred = new Instructor({
* Add a graduate method to a student.
* This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
* If the student's grade is above a 70% let them graduate! Otherswise go back to grading their assignments to increase their score.

nfsldkfsdlkjf
179 changes: 179 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,180 @@
// CODE here for your Lambda Classes

/* Person

First we need a Person class. This will be our base-class
Person receives name age location gender 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 */

//Base-Class below //
class Person {
constructor(attributes) {
this.age = attributes.age;
this.name = attributes.name;
this.location = attributes.location;
this.gender = attributes.gender;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`;
}
}

// testing Person Base-class//
const jt = new Person({
age: "26",
name: "jt",
location: "Palmdale",
gender: "Male"
});
// console.log(jt.speak());
// console.log(jt.age);

const dj = new Person({
age: "25",
name: "dj",
location: "Wyoming",
gender: "Male"
});
// console.log(dj.speak());
// console.log(dj.age);

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

//--- Testing Instructor class--- //
const Ryan = new Instructor({
age: "35",
name: "Ryan",
location: "California",
gender: "Male",
favLanguage: "CSS",
specialty: "Back-End",
catchPhrase: `Try your best`
});

const Josh = new Instructor({
age: "31",
name: "Josh",
location: "New Mexico",
gender: "Male",
favLanguage: "JS",
specialty: "React.js",
catchPhrase: `Don't Repeat Yourself`
});

// console.log(Ryan.specialty);
// console.log(Ryan.catchPhrase);
// console.log(Ryan.favLanguage);

// console.log(Josh.specialty);
// console.log(Josh.catchPhrase);
// console.log(Josh.favLanguage);

///----Students---- ///
class Student extends Person {
constructor(attributes) {
super(attributes);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
}
listsSubjects() {
this.favSubjects.forEach(e => console.log(e));
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}`;
}
}

//----Testing Student Objects---//
const Jordan = new Student({
age: "26",
name: "Jordan",
location: "Palmdale",
gender: "Male",
previousBackground: "Operations",
className: "WEBPT4",
favSubjects: "JS"
});

const Jonathan = new Student({
age: "26",
name: "Jonathan",
location: "New York",
gender: "Male",
previousBackground: "Accounting",
className: "WEBPT4",
favSubjects: "JS"
});

// console.log(Jordan.previousBackground);
// console.log(Jordan.className);
// console.log(Jordan.favSubjects);
// console.log(Jonathan.previousBackground);
// console.log(Jonathan.className);
// console.log(Jonathan.favSubjects);

//---- Project Managers----//

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

//Testing Project Manager Objects//

const Gannon = new ProjectManager({
age: "29",
name: "Gannon",
location: "Detroit",
gender: "Male",
favLanguage: "JavaScript",
specialty: "React.js",
catchPhrase: `How are we doing gents?`,
gradClassName: "CS14",
favInstructor: "Josh Knell"
});

const Carlos = new ProjectManager({
age: "26",
name: "Carlos",
location: "North Carolina",
gender: "Male",
favLanguage: "JavaScript",
specialty: "React.js",
catchPhrase: `Let's Go!`,
gradClassName: "CS12",
favInstructor: "Ryan Hamblin"
});

// console.log(Gannon.favInstructor);
// console.log(Gannon.gradClassName);
// console.log(Carlos.favInstructor);
// console.log(Carlos.gradClassName);
140 changes: 140 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,143 @@ 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 === // Parent
* createdAt
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
*/
class GameObject {
constructor(attributes) {
this.createdAt = attributes.createdAt;
this.dimensions = attributes.dimensions;
}
destroy() {
return `Object was removed from the game.`;
}
}

// testing on an example of GameObject
// const testGameObject = new GameObject({createdAt: 'middle', dimensions: '10x10x10'});
// console.log(testGameObject.destroy()); //'Object was removed from the game.'

/*
=== CharacterStats === // Child
* healthPoints
* name
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

class CharacterStats extends GameObject {
constructor(attributes) {
super(attributes);
this.healthPoints = attributes.healthPoints;
this.name = attributes.name;
}
takeDamage() {
return `${this.name} took damage.`;
}
}

// CharacterStats.prototype.takeDamage = function() {
// return `${this.name} took damage.`;
// }; // ES5 syntax

// Testing CharacterStarts
// const mike = new CharacterStats({healthPoints: 50, name: 'mike', createdAt: 'start', dimensions: '2x2x3'});
// console.log(mike.takeDamage());
// console.log(mike.destroy());

/*
=== Humanoid (Having an appearance or character resembling that of a human.) === // Grandchild
* 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(attributes) {
super(attributes);
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
}

// Humanoid.prototype.greet = function() {
// 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.

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