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
162 changes: 162 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,163 @@
// CODE here for your Lambda Classes
class Person {
constructor(attributes) {
this.name = attributes.name;
this.location = attributes.location;
this.age = attributes.age;
}
speak() {
return `Hello, my name is ${this.name}, and 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}.`; //Passing a parameter into a method means that we don't use the 'this' keyword in the return statement
}
grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}.`;
}
}

class Student extends Person {
constructor(studentAttributes) {
super(studentAttributes);
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
}
listsSubjects() {
this.favSubjects.forEach((subject) => {
console.log(`One of ${this.name}'s favorite subjects is: `, subject);
});
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun their Sprint Challenge on ${subject}.`;
}
}

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

// ************************** PERSON OBJECTS *******************************
const devanee = new Person({
name : 'Devanee Reid',
location : 'The USA',
age : 25,
});

const abdel = new Person({
name : 'Idir Abderahim',
location : 'France',
age : 23,
});

const hui = new Person({
name : 'XuHui Zhu',
location : 'The USA',
age : 20,
});

console.log(devanee.speak());
console.log('My name is ', hui.name);
console.log('Name:', abdel.name, 'Location:', abdel.location);

// ************************** INSTRUCTOR OBJECTS *******************************

const brit = new Instructor({
name : 'Brit Hemming',
location : 'Canada',
age : 30,
favLanguage : 'JavaScript',
specialty : 'JavaScript',
catchPhrase : 'Please be professional.',
});

const christina = new Instructor({
name : 'Christina Gorton',
location : 'Costa Rica',
age : 35,
favLanguage : 'CSS',
specialty : 'CSS, React',
catchPhrase : 'Any clarifying questions?',
});

console.log("Brit's favorite language is ", brit.favLanguage);
console.log(brit.grade(devanee, 'React'));
console.log('Christina always asks ', christina.catchPhrase);
console.log(christina.speak(), 'My specialty is making creative art in ', christina.favLanguage);
console.log(christina.demo('React'));

// ************************** STUDENT OBJECTS *******************************

const stephanie = new Student({
name : 'Stephanie Butenhof',
location : 'Oklahoma',
age : 33,
previousBackground : 'stay-at-home-mom',
className : 'WEB25',
favSubjects : [ 'HTML', 'CSS' ],
});

const nate = new Student({
name : 'Nathaniel Mosco',
location : 'Georgia',
age : 28,
previousBackground : 'nurse',
className : 'WEB23',
favSubjects : [ 'React', 'JavaScript', 'C++' ],
});

console.log(nate.speak());
stephanie.listsSubjects(); // Console.log is returned inside the function.
nate.listsSubjects(); // Console.log is returned inside the function.
console.log(stephanie.PRAssignment('JavaScript-III'));
console.log(nate.sprintChallenge('Preprocessing-II'));

// ************************** TEAM LEAD OBJECTS *******************************

const mikaela = new TeamLeads({
name : 'Mikaela Currier',
location : 'Georgia',
age : 23,
favLanguage : 'Ruby',
specialty : 'JavaScript',
catchPhrase : "It's standy time!",
gradClassName : 'WEB20',
favInstructor : 'Josh Knell',
});

const justin = new TeamLeads({
name : 'Justin Trombley',
location : 'New York',
age : 26,
favLanguage : 'JavaScript',
specialty : 'JavaScript, React',
catchPhrase : "I'm always here if you need me.",
gradClassName : 'WEB21',
favInstructor : 'Dustin Myers',
});

console.log(mikaela.speak());
console.log(justin.demo('Constructor Functions'));
console.log(mikaela.standUp('WEB23-mikaela'));
console.log(justin.debugsCode(nate, 'React'));
135 changes: 135 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,138 @@ 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 = 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
*/

class CharacterStats extends GameObject {
constructor(charAttributes) {
super(charAttributes);
this.healthPoints = charAttributes.healthPoints;
this.name = charAttributes.name;
}

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(humanAttributes) {
super(humanAttributes);
this.team = humanAttributes.team;
this.weapons = humanAttributes.weapons;
this.language = humanAttributes.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 your 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!