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

class Instructor extends Person {
constructor(InstructorAttr) {
super(InstructorAttr);
this.specialty = InstructorAttr.specialty;
this.favLanguage = InstructorAttr.favLanguage;
this.catchPhrase = InstructorAttr.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}`;
}
grade(student, subject) {
return `${student} receives a perfect score on ${subject}`;
}
scoreCard(obj) {
let plusOrMinus = Math.random() < 0.5 ? -1 : 1;
let numGrade = Math.ceil(Math.random() * 100) * plusOrMinus;
let finalNum = obj + numGrade;
return finalNum;


}
}

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

listSubjects(favSubjects) {
return this.favSubjects;
}
PRAssignment(subject) {
return `${this.name} has submitted a PR Assignment for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun the sprint challenge on ${subject}!`;
}
graduate() {
if (this.grade >= 70) {
return `Your final grade is ${student_one.grade} you passed`;

} else {
return `Your final grade is ${student_one.grade} you will need to flex`;
}
}
}

class TeamLead extends Instructor {
constructor(TeamLeadAttr) {
super(TeamLeadAttr);
this.gradeClassName = TeamLeadAttr.gradeClassName;
this.favInstructor = TeamLeadAttr.favInstructor;
}
standUp(slackChannel) {
return `${this.name} announces to ${slackChannel}, @channel standy times!`;
}
debugsCode(student, subject) {
return `${this.name} debugs ${student_one.name}'s code on ${student_one.className}`;
}

}
const instructor_one = new Instructor({
name: 'Pace',
age: 26,
location: 'Mesa',
specialty: 'Javascript',
favLanguage: 'Spanish',
catchPhrase: 'Logitech is awesome'

});

const student_one = new Student({
name: 'Ben',
age: 36,
location: 'Mesa',
previousBackground: 'Customer Service',
className: 'Javascript IV',
favSubjects: ['HTML', 'CSS', 'Javascript'],
grade: instructor_one.scoreCard(75)

});



const teamLead_one = new TeamLead({
name: 'Julie',
age: 25,
location: 'New York',
favLanguage: 'React',
catchPhrase: 'Wubba lubba dub dub',
gradeClassName: 'WEBFT8',
favInstructor: 'Pace Ellsworth'
});

console.log(student_one.PRAssignment('HTML'));
console.log(instructor_one.demo('Classes and Constructors'));
console.log(`${instructor_one.name} thinks ${instructor_one.catchPhrase}`);
console.log(teamLead_one.standUp('WebPT11'));
console.log(instructor_one.grade('Ben', 'Javascript IV'));
console.log(`${teamLead_one.name} says ${teamLead_one.catchPhrase}`);
console.log(student_one.graduate(instructor_one.scoreCard()));
213 changes: 213 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,220 @@
Prototype Refactor

1. Copy and paste your code or the solution from yesterday
function GameObject(attribute) {
this.createdAt = attribute.createdAt;
this.name = attribute.name;
this.dimensions = attribute.dimensions;
}
GameObject.prototype.destroy = function () {
return `${this.name} was removed from the game.`;
};

function CharacterStats(stats) {
GameObject.call(this, stats);
this.healthPoints = stats.healthPoints;
}

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

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


function Humanoid(profile) {
CharacterStats.call(this, profile);
this.team = profile.team;
this.weapons = profile.weapons;
this.language = profile.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: {
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 Jedi = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4
},
healthPoints: 25,
name: 'Luke',
team: 'Rebel',
weapons: ['LightSaber'],
language: 'Common'
});
const Sith = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4
},
healthPoints: 40,
name: 'Darth Vader',
team: 'Imperial',
weapons: ['LightSaber', 'Blaster'],
language: 'Common'
});
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.

*/
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.`;
}
}

class CharacterStats extends GameObject {
constructor(stats) {
super(stats);

this.healthPoints = stats.healthPoints;
}
takeDamage() {
return `${this.name} took damage.`;
}
}

class Humanoid extends CharacterStats {
constructor(profile) {
super(profile);

this.team = profile.team;
this.weapons = profile.weapons;
this.language = profile.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
}
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 Jedi = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4
},
healthPoints: 25,
name: 'Luke',
team: 'Rebel',
weapons: ['LightSaber'],
language: 'Common'
});
const Sith = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4
},
healthPoints: 40,
name: 'Darth Vader',
team: 'Imperial',
weapons: ['LightSaber', 'Blaster'],
language: 'Common'
});

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(`${Jedi.name} hits ${Sith.name} with ${Jedi.weapons} `);
console.log(Sith.takeDamage());
console.log(`${Sith.name} shoots ${Jedi.name} with ${Sith.weapons[1]}`);
console.log(Jedi.takeDamage());