Skip to content
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

almost done #678

Open
wants to merge 1 commit 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
157 changes: 157 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,158 @@
// CODE here for your Lambda Classes
class Person {
constructor(personAttrs) {
this.name = personAttrs.name;
this.age = personAttrs.age;
this.location = personAttrs.location;
this.gender = personAttrs.gender;
}

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

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

demo(subject) {
return `Today we are learning about ${subject}`;
}

grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}`
}

adjustGrade(student) {
let points = Math.round(Math.random() * 100);
if (student.grade >= 100) {
student.grade -= points;
return `${points} points are subtracted from ${student.name}'s grade. ${student.name}'s current grade is ${student.grade}`;
} else {
student.grade += points;
return `${points} points are added to ${student.name}'s grade. ${student.name}'s current grade is ${student.grade}`;
}
}
}

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

sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}`;
}
listsSubjects() {
this.favSubjects.map(item => console.log(item));
}

PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`;
}


graduate() {
if (this.grade >= 70) {
return `${this.name} has graduated with a final grade of ${this.grade}!`;
} else {
let diff = 70 - this.grade;
this.grade += diff;
return `After more grading, ${diff} points were earned and ${this.name} has graduated with a final grade of ${this.grade}!`;
}
}
}

class ProjectManager extends Instructor {
constructor(managerAttrs) {
super(managerAttrs);
this.gradClassName = managerAttrs.gradClassName;
this.favInstructor = managerAttrs.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 brit = new Instructor({
name: "Brit",
location: "Canada",
age: 31,
gender: "female",
favLanguage: "JavaScript",
specialty: "Front-end",
catchPhrase: `We'll go ahead and do some pair programming. `
});

const don = new Instructor({
name: "Don",
location: "Indiana",
age: 38,
gender: "male",
favLanguage: "CSS",
specialty: "Fullstack",
catchPhrase: `Ready`
});

const john = new Student({
name: "Hunter",
location: "Salt Lake City",
age: 21,
gender: "male",
favSubjects: ["Javascript"],
grade: 100
});

const andi = new Student({
name: "andy",
location: "Tokyo",
age: 26,
gender: "female",
favSubjects: ["Javascript"],
grade: 100
});

const shawn = new ProjectManager({
name: "Shawn",
location: "Toledo",
age: 58,
gender: "male",
gradClassName: "CS1"
});

const tina = new ProjectManager({
name: "Tina",
location: "Scranton",
age: 30,
gender: "female",
gradClassName: "CS2"
});


console.log(tina.speak());
console.log(jen.listsSubjects());
console.log(shawn.gender);
console.log(tina.debugsCode(jen, "Javascript"));
console.log(shawn.standUp("FSW14"));
console.log(jen.sprintChallenge("Javascript"));
console.log(brit.demo("React"));
console.log(brit.grade(jen, "CSS"));
console.log(shawn.speak());
console.log(john.PRAssignment("Responsive Design"));
console.log(don.catchPhrase);
console.log(tina.adjustGrade(jen));
console.log(jen.graduate(brit));
220 changes: 219 additions & 1 deletion assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,222 @@ 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.

*/
*/ class GameObject{
constructor(gameObejectAttributes){
this.createdAt = gameObejectAttributes.createdAt;
this.dimensions = gameObejectAttributes.dimensions;
}
//methods for this ^ constructor
destroy() {
return `${this.name} was removed from the game`;
}
}
//Build next constructor
class CharacterStats{
constructor(characterStatsAttribute){
this.hp = characterStatsAttribute.hp;
this.name = characterStatsAttribute.name;
GameObject.call(this, characterStatsAttribute);
}

// Inheritance
class CharacterStats extends GameObject{
constructor(characterStatsAttribute)
super(characterStatsAttribute);
}

//methods for this ^ constructor
takeDamage() {
return `${this.name} took damage`;
}
}
//Test you work by uncommenting these 3 objects and the list of console logs below:
class Humanoid{
constructor(humanoidAttributes){
this.faction = humanoidAttributes.faction;
this.weapons = humanoidAttributes.weapons;
this.language = humanoidAttributes.language;
CharacterStats.call(this,humanoidAttributes);
}

Humanoid.prototype = Object.create(CharacterStats.prototype);
//Humanoid methods under here.
//greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
//^^ building above.
greet() {
return `${this.name} says 'hI' in ${this.language}`;
}
}
const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
hp: 5,
name: 'Bruce',
faction: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
});


const swordsman = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 2,
height: 2,
},
hp: 15,
name: 'Sir Mustachio',
faction: 'The Round Table',
weapons: [
'Giant Sword',
'Shield',
],
language: 'Common Toungue',
});

const archer = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
hp: 10,
name: 'Lilith',
faction: 'Misiones, Argentina',
weapons: [
'Bow',
'Dagger',
],
language: 'Elvish',
});
// new constructor
class Villian{
constructor(villianAttributes){
Humanoid.call(this, villianAttributes);
this.badBreath = villianAttributes.badBreath;
this.opponentHealth = villianAttributes.opponentHealth;
}
//inherit
Villian.prototype = Object.create(Humanoid.prototype);

//methods
evilLaugh() {
this.opponentHealth -= 10;
return `The villian ${this.name} lets out an evil laugh you will fail because I am ${this.name}`;
}
}
// const failure = new Villian({
// createdAt: new Date(),
// dimensions: {
// length: 1,
// width: 2,
// height: 4,
// },
// hp: 10,
// name: 'Failure',
// faction: 'Misiones, Argentina',
// weapons: [
// 'doubt','low confidence'
// ],
// language: 'Marlarkey',
// badBreath: 'Janky'
// });

class Hero{

constructor(heroAttributes){
this.goodLooks = heroAttributes.goodlooks;
this.opponentHealth = heroAttributes.opponentHealth;

Humanoid.call(this, heroAttributes);
}

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

Hero.prototype.studyHard = function () {
this.opponentHealth -=20;
console.log(this.opponent);
return `The hero ${this.name} studies hard`;
}
Hero.prototype.workHard = function () {
this.opponentHealth -=50;
return `The hero ${this.name} works hard`
}
Hero.prototype.flawlessVictory = function() {
this.opponentHealth-= 30;
return `The hero learns to fight using his weapons ${this.weapons}... and defeats the villian`;
}


const Hunter = new Hero({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
hp: 10,
name: 'Hunter',
faction: 'Misiones, Argentina',
weapons: [
'determination', 'work ethic', 'great instructors', 'supporters', 'the list goes on and on...seriously'
],
language: 'JavaScript',
goodLooks: 'High',
opponentHealth: 100
});

failure = new Villian({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
hp: 10,
name: 'Failure',
faction: 'Misiones, Argentina',
weapons: [
'doubt','low confidence'
],
language: 'Guarani',
badBreath: 'Janky',
opponentHealth: 100
});

console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.hp); // 15
console.log(mage.name); // Bruce
console.log(swordsman.faction); // 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("A new battle is about to begin")
console.log(`The match ${Hunter.name} vs ${failure.name} has begun.`);
console.log(`The villian has the following weapons ${failure.weapons}`);
console.log(`The hero has the following weapons ${Hunter.weapons}`);
console.log(`The villian has the following extra attribute ${failure.badBreath} breath`);
console.log(`The villian speaks the following language ${failure.language}`);
console.log(`The hero speaks the following language ${Hunter.language}`);
console.log(failure.evilLaugh());
console.log(`${Hunter.name} has been reduced, ${Hunter.name} now has ${failure.opponentHealth}`);
console.log(Hunter.studyHard());
console.log(`${failure.name} has been reduced, ${failure.name} now has ${failure.opponentHealth}`);
console.log(Hunter.workHard());
console.log(`${failure.name} has been reduced, ${failure.name} now has ${Hunter.opponentHealth}`) ;
console.log(Hunter.flawlessVictory());
console.log(`${failure.name} has been reduced, ${Hunter.opponentHealth} now has ${Hunter.opponentHealth}`);
console.log(`${Hunter.name} saves the Guarani from conquest!`);