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

class Person {
constructor(settings) {
this.name = settings.name;
this.location = settings.location;
this.age = settings.age;
this.money = settings.money;
this.wage = settings.wage;
this.catchPhrase = settings.catchPhrase;
}

spendMoney(obj, cost) {
this.money -= cost;
console.log(`${this.name} spent ${cost} on a ${obj}. ${this.money} left.`);
}

getPaid() {
this.money += this.wage;
console.log(`${this.name} earned ${this.wage}! ${this.money} left.`);
console.log(this.catchPhrase);
}
}

class Student extends Person {
constructor(settings) {
super(settings);
this.school = settings.school;
this.track = settings.track;
this.toDo = settings.toDo;
}

doAssignment() {
if (this.toDo.length > 0) {
this.toDo.pop();
}
}
}

class Instructor extends Person {
constructor(settings) {
super(settings);
this.school = settings.school;
this.favLanguage = settings.favLanguage;
this.specialty = settings.specialty;
}

giveAssignment(description, student) {
student.toDo.push(description);
}
}

class TeamLead extends Instructor {
constructor(settings) {
super(settings);
this.teamName = settings.teamName;
this.team = settings.team;
}

giveAssignment(description, student) {
if (student === undefined) {
this.team.forEach(s => s.toDo.push(description));
}
else {
super.giveAssignment(description, student);
}
}
}

const person = new Person({
name: "doug dimmadome",
location: "dimmsdale",
age: 40,
money: 1000000,
wage: 10000,
catchPhrase: "owner of the dimmsdale dimmadome"
});
person.spendMoney("parfait", 100000);

const student1 = new Student({
name: "ben hall",
location: "america",
age: 26,
money: 123456,
wage: 123,
catchPhrase: "Ok",
school: "lambda",
track: "full stack web PT 11",
toDo: [],
});
const student2 = new Student({
name: "ben hall 2",
location: "america 2",
age: 26,
money: 123456,
wage: 123,
catchPhrase: "Ok again",
school: "lambda 2",
track: "full stack web PT 12",
toDo: [],
});
const instructor = new Instructor({
name: "John Smith",
location: "canada",
age: 6000,
money: 1000000000,
wage: 0,
catchPhrase: "H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ",
school: "Lambda",
favLanguage: "javascript",
specialty: "baking",
});
const teamLead = new TeamLead({
name: "Beethoven",
location: "Germany",
age: 50,
money: 2000,
wage: 42,
catchPhrase: "Can you say that again?",
school: "Lambda",
favLanguage: "music",
specialty: "piano",
teamName: "fortes",
team: [student1, student2],
});

teamLead.spendMoney("piano", 1000);
teamLead.getPaid();
instructor.giveAssignment("Javascript-IV", student1);
instructor.spendMoney("book", 0.5);
teamLead.giveAssignment("compose piano sonata");
student1.doAssignment();
student2.doAssignment();

console.log(student1);
console.log(student2);
console.log(instructor);
console.log(teamLead);
130 changes: 130 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,133 @@ 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 ===
* 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(settings) {
this.createdAt = settings.createdAt;
this.name = settings.name;
this.dimensions = settings.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(settings) {
super(settings);
this.healthPoints = settings.healthPoints;
}

takeDamage() {
return `${this.name} took damage.`
}
}

/*let test = new CharacterStats("home", "bob", "2x2", "500");
console.log(test.takeDamage());
console.log(test.destroy());*/

/*
=== 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(settings) {
super(settings);
this.team = settings.team;
this.weapons = settings.weapons;
this.language = settings.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 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.