Skip to content

Jun Hyuk Kim: Javascript IV - Complete + Stretch #125

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const fred = new Instructor({
* `gradClassName`: i.e. CS1
* `favInstructor`: i.e. Sean
* ProjectManangers have the following Methods:
* `standUp` a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​
* `standUp` a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!​​​​​`
* `debugsCode` a method that takes in a student object and a subject and logs out `{name} debugs {student.name}'s code on {subject}`

#### Stretch Problem
Expand Down
109 changes: 109 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
// CODE here for your Lambda Classes
class Person {
constructor(personAttributes) {
this.name = personAttributes.name;
this.age = personAttributes.age;
this.location = personAttributes.location;
this.gender = personAttributes.gender;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`;
}
}

class Instructor extends Person{
constructor(instructorAttributes){
super(instructorAttributes);
this.speciality = instructorAttributes.speciality;
this.favLanguage = instructorAttributes.favLanguage;
this.catchPhrase = instructorAttributes.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}`;
}
grade(student) {
let plusorMinus = Math.random() < 0.5 ? -1 : 1;
let random = Math.floor(Math.random() * 40);
student.grade = student.grade - (plusorMinus * random);
return `${student.name} currently has a grade of ${student.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;
}
listSubjects() {
this.favSubjects.forEach(subject => console.log(subject));
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`;
}
sprintChallenge(subject){
return `${this.name} has begun a sprint challenge on ${subject}`;
}
graduate() {
if (this.grade >= 70) {
return `${this.name} has a grade of ${this.grade} and is ready to graduate!`;
} else {
return `${this.name} has a grade of ${this.grade} and needs ${70-this.grade} more to graduate.`
}
}
}

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

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

const joe = new Student({
name: 'Joe',
location: 'Bedrock',
age: 37,
gender: 'male',
previousBackground: 'Rapper',
className: 'CS100',
favSubjects: ['HTML', 'React', 'D3'],
grade: 100
});

const steve = new ProjectManager({
name: 'Steve',
location: 'Bedrock',
age: 37,
gender: 'male',
gradClassName: 'CS1',
favInstructor: 'Josh'
});

console.log(fred.demo('React'));
console.log(fred.grade(joe, 'React'));
joe.listSubjects();
console.log(joe.PRAssignment('JavaScript'));
console.log(joe.sprintChallenge('Python'));
console.log(steve.standUp('CS12'));
console.log(steve.debugsCode(joe, 'JavaScript'));
console.log(steve.grade(joe));
console.log(joe.graduate());
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 `${this.name} 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