Skip to content

Ashwin Sundararajan #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
125 changes: 125 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,126 @@
// CODE here for your Lambda Classes
class Person {
constructor(props) {
this.name = props.name;
this.age = props.age;
this.gender = props.gender;
this.location = props.location;
}

speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}

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

demo(subject) {
console.log(`Today we are learning about ${subject}`);
}

grade(student, subject) {
let rand = Math.floor(-50 + Math.random() * 100);
student.grade += rand;
student.grade = Math.max(0, Math.min(student.grade, 100));
console.log(`${student.name} receives ${student.grade} on ${subject}`);
}
}

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

listsSubjects() {
this.favSubjects.forEach(x => console.log(x));
}

PRAssigment(subject) {
console.log(`${this.name} has submitted a PR for ${subject}`);
}

sprintChallenge(subject) {
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}

graduate(instructor, subject) {
while (this.grade <= 70) {
instructor.grade(this, subject);
}
console.log(
`${this.name} has successfully graduated by scoring ${this.grade}!`
);
}
}

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

standUp(channel) {
console.log(`${this.name} announces to ${channel}`);
}

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

const fred = new Instructor({
name: "Fred",
location: "Bedrock",
age: 37,
gender: "male",
favLanguage: "JavaScript",
specialty: "Front-end",
catchPhrase: `Yabba dabba doo`
});

const dovahkin = new Student({
name: "Dovahkin",
location: "Tamriel",
age: 30,
gender: "male",
className: "CS12",
favSubjects: ["JavaScript", "C", "Python"],
previousBackground: "Dragon Slayer",
grade: 70
});

const barney = new ProjectManager({
name: "Barney",
location: "Bedrock",
age: 27,
gender: "male",
favLanguage: "Python",
specialty: "DevOps",
catchPhrase: `Don't forget the homies`,
gradClassName: "CS3",
favInstructor: "Fred"
});

fred.speak();
fred.demo("React");
fred.grade(dovahkin, "Computer Architecture");
dovahkin.speak();
dovahkin.listsSubjects();
dovahkin.PRAssigment("JavaScript-II");
dovahkin.sprintChallenge("Redux");
barney.speak();
barney.demo("Data Structures");
barney.standUp("#cs12");
barney.debugsCode(dovahkin, "React");
dovahkin.graduate(fred, "Computer Architecture");
78 changes: 40 additions & 38 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@
// Today 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.

function GameObject(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}

GameObject.prototype.destroy = function() {
return `Object was removed from the game.`;
};
class GameObject {
constructor(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}

function CharacterStats(characterStatsOptions) {
GameObject.call(this, characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.name = characterStatsOptions.name;
destroy() {
return `${this.name} was removed from the game`;
}
}

CharacterStats.prototype = Object.create(GameObject.prototype);
class CharacterStats extends GameObject {
constructor(options) {
super(options);
this.hp = options.hp;
this.name = options.name;
}

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

function Humanoid(humanoidOptions) {
CharacterStats.call(this, humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
takeDamage() {
return `${this.name} took damage.`;
}
}

Humanoid.prototype = Object.create(CharacterStats.prototype);
class Humanoid extends CharacterStats {
constructor(options) {
super(options);
this.faction = options.faction;
this.weapons = options.weapons;
this.language = options.language;
}

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

const mage = new Humanoid({
createdAt: new Date(),
Expand All @@ -44,10 +46,10 @@ const mage = new Humanoid({
height: 1
},
hp: 5,
name: 'Bruce',
faction: 'Mage Guild',
weapons: ['Staff of Shamalama'],
language: 'Common Toungue'
name: "Bruce",
faction: "Mage Guild",
weapons: ["Staff of Shamalama"],
language: "Common Toungue"
});

const swordsman = new Humanoid({
Expand All @@ -58,10 +60,10 @@ const swordsman = new Humanoid({
height: 2
},
hp: 15,
name: 'Sir Mustachio',
faction: 'The Round Table',
weapons: ['Giant Sword', 'Shield'],
language: 'Common Toungue'
name: "Sir Mustachio",
faction: "The Round Table",
weapons: ["Giant Sword", "Shield"],
language: "Common Toungue"
});

const archer = new Humanoid({
Expand All @@ -72,10 +74,10 @@ const archer = new Humanoid({
height: 4
},
hp: 10,
name: 'Lilith',
faction: 'Forest Kingdom',
weapons: ['Bow', 'Dagger'],
language: 'Elvish'
name: "Lilith",
faction: "Forest Kingdom",
weapons: ["Bow", "Dagger"],
language: "Elvish"
});

console.log(mage.createdAt); // Today's date
Expand Down