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

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

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

finalGrade(){
return Math.floor(Math.random() * 100);
}
}

class Student extends Person {
constructor(att) {
super(att);
this.previousBackground = att.previousBackground;
this.className = att.className;
this.favSubjects = att.favSubjects;
}

listsSubjects() {
return this.favSubjects.forEach(function (list) {
console.log(list);
});
}

PRAssignment(student, subject) {
return `${student} has submitted a PR for ${subject}`;
}

sprintChallenge(student, subject) {
return `${student} has begun sprint challenge on ${subject}`;
}
}

class ProjectManager extends Instructor {
constructor(att) {
super(att);
this.gradClassName = att.gradClassName;
this.favInstructor = att.favInstructor;
}

standUp(name, channel) {
return `${name} announces to ${channel}, standy times!​​​​​`;
}

debugsCode(student, subject) {
return `${this.name} debugs ${student}'s code on ${subject}`;
}
}

const adam = new Person({
name: 'Adam',
location: 'Amsterdam',
age: 37,
gender: 'male',
});

const betsy = new Person({
name: 'Betsy',
location: 'Bloomington',
age: 30,
gender: 'female',
});

const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});

const caitlin = new Instructor({
name: 'Caitlin',
location: 'Castlerock',
age: 45,
gender: 'female',
favLanguage: 'C#',
specialty: 'Back-end',
catchPhrase: `Just do it`
});

const devin = new Student({
name: 'Devin',
location: 'Detroit',
age: 27,
gender: 'male',
className: 'CS132',
favSubjects: ['Html', 'CSS', 'JavaScript'],
grade: 85
});

const evelyn = new Student({
name: 'Evelyn',
location: 'Egypt',
age: 23,
gender: 'female',
className: 'CS132',
favSubjects: ['Html', 'CSS', 'JavaScript'],
grade: 90
});

const gretchen = new ProjectManager({
name: 'Gretchen',
location: 'Grayson',
age: 42,
gender: 'female',
gradClassName: 'CS1',
favInstructor: 'Sean'
});

const henry = new ProjectManager({
name: 'Henry',
location: 'Hillsdale',
age: 46,
gender: 'male',
gradClassName: 'CS12',
favInstructor: 'Seanie'
});


console.log(adam.location);
console.log(betsy.speak());
console.log(fred.demo('Javascript'));
console.log(caitlin.grade(devin.name, "Javascript"));
devin.listsSubjects();
console.log(evelyn.PRAssignment(evelyn.name, 'Javascript'));
console.log(evelyn.sprintChallenge(devin.name, 'Css'));
console.log(gretchen.standUp(henry.name, 'Web18'));
console.log(henry.debugsCode(devin.name, 'Java'));
198 changes: 198 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,202 @@ 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(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(health) {
super(health)
this.healthPoints = health.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(avatar) {
super(avatar);
this.team = avatar.team;
this.weapons = avatar.weapons;
this.language = avatar.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}`;
};
}


// function Hero(avatar) {
// this.team = avatar.team;
// this.weapons = avatar.weapons;
// this.language = avatar.language;
// Humanoid.call(this, avatar);

// }

// Hero.prototype = Object.create(Humanoid.prototype);

// Hero.prototype.hp = function () {
// if (this.healthPoints <= 0) {
// return this.destroy();
// } else {
// return "Still alive!";
// }
// };

// function Villain(avatar) {
// this.team = avatar.team;
// this.weapons = avatar.weapons;
// this.language = avatar.language;
// Hero.call(this, avatar);
// }

// Villain.prototype = Object.create(Hero.prototype);



/*
* 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',
});

// const good = new Hero({
// createdAt: new Date(),
// dimensions: {
// length: 2,
// width: 3,
// height: 6,
// },
// healthPoints: 20,
// name: 'Sheera',
// team: 'Forest Kingdom',
// weapons: [
// 'Slingshot',
// 'Dagger',
// ],
// language: 'Elvish',
// });

// const bad = new Villain({
// createdAt: new Date(),
// dimensions: {
// length: 1,
// width: 1,
// height: 7,
// },
// healthPoints: 10,
// name: 'Gargamel',
// team: 'Forest Kingdom',
// weapons: [
// 'Rock',
// 'Stick',
// ],
// language: 'Common Tongue',
// });

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.
// console.log(good.hp());
// console.log(bad.hp())