Skip to content
Open
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ const fred = new Instructor({
* Extend the functionality of the Student by adding a prop called grade and setting it equal to a number between 1-100.
* Now that our students have a grade build out a method on the Instructor (this will be used by _BOTH_ instructors and PM's) that will randomly add or subtract points to a student's grade. _Math.random_ will help.
* Add a graduate method to a student.
* This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
* This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School.
* If the student's grade is above a 70% let them graduate! Otherwise go back to grading their assignments to increase their score.
190 changes: 190 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,191 @@
// CODE here for your Lambda Classes
class Person {
constructor(attrs) {
this.name = attrs.name;
this.age = attrs.age;
this.location = attrs.location;
}
// PERSON FUNCTIONS
speak(){
console.log(`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;
}
// INSTRUCTOR FUNCTIONS
demo(subject) {
console.log("Today we are learning about " + subject);
}
grade(student, subject) {
console.log(student.name + " receives a perfect score on " + subject);
}
gradeStudent(student) {
let points = Math.floor((Math.random() * 20) + 1);
var plusOrMinus = Math.random() < 0.5 ? -1 : 1;
points = points * plusOrMinus;
student.grade = student.grade + points;
console.log(this.name + "has adjusted " + student.name + "'s grade by " + points + " points");
console.log(student.name + "'s new 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;
}
// STUDENT FUNCTIONS
listsSubjects(){
this.favSubjects.forEach((element) => { console.log(element); });
}
PRAssignment(subject) {
console.log(this.name + " has submitted a PR for " + subject);
}
sprintChallenge(subject) {
console.log(this.name + " has begun the sprint challenge on " + subject);
}
graduate() {
if (this.grade >= 70) { console.log(this.name + " has graduated Lambda School with a grade of " + this.grade + "!"); }
else { console.log(this.name + " has failed Lambda School with a grade of " + this.grade + ". :("); }
}
}

class ProjectManagers extends Instructor {
constructor(pmAttrs){
super(pmAttrs);
this.gradClassName = pmAttrs.gradClassName;
this.favInstructor = pmAttrs.favInstructor;
}
// PROJECTMANAGERS FUNCTIONS
standup(slackChannel) {
console.log(this.name + " announces to " + slackChannel + ", @channel standy times!");
}
debugsCode(studentObj, subject) {
console.log(this.name + " debugs " + studentObj.name + "'s code on " + subject);
}
}


// STUDENT OBJECTS
const justin = new Student({
name: "Justin Renninger",
age: 25,
location: "Pennsylvania",
previousBackground: "Computer Science & Chemistry",
className: "Full Stack Web Development",
favSubjects: ['OOP', 'Polyurethanes'],
grade: 75
});

const will = new Student({
name: 'Will Smith',
age: '40',
location: 'California',
previousBackground: 'Action Movies',
className: 'Full Stack Web Development',
favSubjects: ['The Fresh Prince', 'Anything with action'],
grade: 85
});

const john = new Student({
name: 'John Wick',
age: 30,
location: 'Unknown',
previousBackground: 'Hitman',
className: 'Full Stack Web Development',
favSubjects: ['Guns', 'Stealth'],
grade: 70
});

// INSTRUCTOR OBJECTS
const fred = new Instructor({
name: 'Fred Flintstone',
location: 'Bedrock',
age: 37,
favLanguage: 'Ruby On Rails',
specialty: 'Front-end',
catchPhrase: `Yabba Dabba Doo`
});

const dan = new Instructor({
name: 'Dan Levy',
location: 'Bedrock',
age: 32,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});

const colin = new Instructor({
name: 'Colin Frasier',
location: 'New Jersey',
age: 49,
favLanguage: 'C++',
specialty: 'Computer Engineering',
catchPhrase: `If you don't use get/set, you're wrong.`
});

// PROJECT MANAGER OBJECTS
const ww = new ProjectManagers({
name: 'Wonder Woman',
age: 26,
location: 'Paradise Island',
favLanguage: 'The Common Tongue',
specialty: 'Whipping things',
catchPhrase: 'By The Goddes!',
gradClassName: 'Full Stack Web Development',
favInstructor: 'Zeus'
});

const batman = new ProjectManagers({
name: 'Bruce Wayne',
age: 35,
location: 'Bat Cave',
favLanguage: 'Sonar',
specialty: 'Being emo',
catchPhrase: "I'm Batman",
gradClassName: 'Full Stack Web Development',
favInstructor: 'Alfred'
});

const walter = new ProjectManagers({
name: 'Walter White',
age: 60,
location: 'Albuquerque',
favLanguage: 'English',
specialty: 'Chemistry',
catchPhrase: "Jesse!",
gradClassName: 'Full Stack Web Development',
favInstructor: 'Dan Levy'
});

console.log(justin.previousBackground); //-------------"Computer Science & Chemistry"
console.log(fred.favLanguage); //----------------------"Ruby On Rails"
console.log(batman.catchPhrase); //--------------------"I'm Batman"

walter.speak(); //-------------------------------------"Hello my name is Walter White, I am from Albuquerque"
fred.demo(fred.favLanguage); //------------------------"Today we are learning about Ruby On Rails"
dan.grade(john, 'Javascript IV'); //-------------------"John Wick receives a perfect score on Javascript IV"
justin.listsSubjects(); //-----------------------------"OOP \n Polyurethanes"
will.PRAssignment('Javascript IV'); //-----------------"Will Smith has submitted a PR for Javascript IV"
john.sprintChallenge('Applied Javascript'); //---------"John Wick has begun the sprint challenge on Applied Javascript"
batman.standup('Web21'); //----------------------------"Bruce Wayne announces to Web21, @channel standy times!"
walter.debugsCode(justin, "JavaScript IV"); //---------"Walter White debugs Justin Renninger's code on JavaScript IV"
fred.gradeStudent(justin);
dan.gradeStudent(justin);
justin.graduate();

let int = function numberRange(min, max){
return Math.round(Math.random() * (max-min)) + min;
}

console.log(int(1, 100));
177 changes: 177 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,180 @@ 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(gameStuff) {
this.createdAt = gameStuff.createdAt;
this.name = gameStuff.name;
this.dimensions = gameStuff.dimensions;
}
destroy() {
return this.name + " was removed from the game.";
}
}


/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
class CharacterStats extends GameObject {
constructor(charAttributes) {
super(charAttributes);
this.healthPoints = charAttributes.healthPoints;
}

takeDamage() {
return this.name + " took damage.";
}

attack(target) {
this.attackDmg = Math.floor((Math.random() * 50) + 1);
if (this.healthPoints > 0 && target.healthPoints > 0)
console.log(this.name + " attacks " + target.name + " with " + this.weapons + " for " + this.attackDmg + " points of damage.");
if (this.healthPoints <= 0) {
return this.name + " cannot attack, it is dead.";
}
else if (target.healthPoints <= 0) {
return this.name + " beats up " + target.name + "'s dead body.";
}
else {
target.healthPoints = target.healthPoints - this.attackDmg;
if (target.healthPoints <= 0)
return this.name + " has killed " + target.name + "!";
else
return target.name + " is still alive with " + target.healthPoints + " health points left";
}
}
}
/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
* weapons
* language
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/
class Humanoid extends CharacterStats {
constructor(humAttributes) {
super(humAttributes);
this.team = humAttributes.team;
this.weapons = humAttributes.weapons;
this.language = humAttributes.language;
this.attackDmg = humAttributes.attackDmg;
}
greet() {
return this.name + " offers a greeting in " + this.language;
}
}


class Villian extends Humanoid {
constructor(villStats) {
super(villStats);
}
}

class Hero extends Humanoid {
constructor(heroStats) {
super(heroStats);
}
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
* Instances of CharacterStats should have all of the same properties as GameObject.
*/

// Test you work by un-commenting these 3 objects and the list of console logs below:


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 javascript = new Villian({
name: 'Javascript',
healthPoints: 100,
weapons: 'Demoralization',
language: 'idfk',
attackDmg: Math.floor((Math.random() * 50) + 1),
remainingHealth: 100
});

const web21 = new Hero({
name: 'Web21',
healthPoints: 100,
weapons: 'Josh Knell',
attackDmg: Math.floor((Math.random() * 50) + 1),
remainingHealth: 100
});







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(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.

// STRETCH
console.log(web21.attack(javascript));
console.log(javascript.attack(web21));
console.log(web21.attack(javascript));
console.log(javascript.attack(web21));
console.log(web21.attack(javascript));
console.log(javascript.attack(web21));
console.log(web21.attack(javascript));
console.log(javascript.attack(web21));