Skip to content

Adam Lee: Javascript-IV #132

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 5 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
144 changes: 143 additions & 1 deletion assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,143 @@
// CODE here for your Lambda Classes
class Person {
constructor (attributes) {
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
this.gender = attributes.gender;
}
speak () {
return `Hello my name is ${this.name}, I'm from ${this.location}.`;
}
}

class Instructor extends Person {
constructor (instAttributes) {
super(instAttributes);
this.specialty = instAttributes.specialty;
this.favLanguage = instAttributes.favLanguage;
this.catchPhrase = instAttributes.catchPhrase;
}
demo (subject) {
return `Today we are learning about ${subject}`;
}
grade (studentObj, subject) {
return `${studentObj.name} receives a perfect score on ${subject}`;
}
scoring (studentObj) {
const randomNum = Math.random();
const startingGrade = studentObj.grade;
const scoreAmount = Math.floor(Math.floor(Math.random()*10));
if (randomNum < 0.5) {
studentObj.grade -= scoreAmount;
return `${studentObj.name}'s grade has changed from a ${startingGrade} to a ${studentObj.grade}`;
} else {
studentObj.grade += scoreAmount;
return `${studentObj.name}'s grade has changed from a ${startingGrade} to a ${studentObj.grade}`;
}
}
}

class Student extends Person {
constructor (studentAttributes) {
super(studentAttributes);
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
this.grade = studentAttributes.grade;
}
listsSubjects () {
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}`;
}
graduate () {
if (this.grade > 70) {
return `${this.name} has above a 70% and is ready to graduate from Lambda School!`;
}
return `${this.name} has below a 70% and needs to complete more assignments`;
}
}

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

const terrance = new Instructor({
name: 'Terrance',
location: 'Canada',
age: 32,
gender: 'male',
favLanguage: 'HTML',
specialty: 'Back-end',
catchPhrase: `I'm not your buddy friend.`
});

const terrance = new Instructor({
name: 'Phillip',
location: 'Canada',
age: 32,
gender: 'male',
favLanguage: 'Perl',
specialty: 'Back-end',
catchPhrase: `I'm not your friend guy.`
});

const eric = new Student({
name: 'Eric',
location: 'South Park',
age: 8,
gender: 'male',
previousBackground: 'Just graduated 3rd grade',
className: 'End User',
favSubjects: ['Recess', 'Video Games', 'A-hole 101'],
grade: 70
});

const kyle = new Student({
name: 'Kyle',
location: 'South Park',
age: 8,
gender: 'male',
previousBackground: 'Just graduated 3rd grade',
className: 'Full-Stack Web Dev',
favSubjects: ['Math', 'English', 'Science'],
grade: 95
});

const al = new ProjectManager({
name: 'Al Gore',
location: 'Washington DC',
age: 70,
gender: 'male',
favLanguage: 'CSS',
specialty: 'Web Pages',
catchPhrase: `ManBearPig is half man, half bear, and half pig.`,
gradClassName: 'CS12',
favInstructor: 'Josh (of course)'
});

const garrison = new ProjectManager({
name: 'Mr Garrison',
location: 'South Park',
age: 55,
gender: 'male',
favLanguage: 'Python',
specialty: 'Front-end',
catchPhrase: `You can say that again, Mr. Hat`,
gradClassName: 'CS9',
favInstructor: 'Mr Hat'
});
55 changes: 27 additions & 28 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@
// 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;
class GameObject {
constructor (options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}
destroy () {
return `Object was removed from the game.`;
}
}

GameObject.prototype.destroy = function() {
return `Object was removed from the game.`;
};

function CharacterStats(characterStatsOptions) {
GameObject.call(this, characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.name = characterStatsOptions.name;
class CharacterStats extends GameObject {
constructor (characterStatsOptions) {
super(characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.name = characterStatsOptions.name;
}
takeDamage () {
return `${this.name} took damage.`;
}
}

CharacterStats.prototype = Object.create(GameObject.prototype);

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;
class Humanoid extends CharacterStats {
constructor (humanoidOptions) {
super(humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
}
greet () {
return `${this.name} offers a greeting in ${this.language}.`;
}
}

Humanoid.prototype = Object.create(CharacterStats.prototype);

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

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down