Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9225b5a
copied all of prototype.js into prototype-refactor.js
CJLucido Sep 19, 2019
3197722
converted GameObject to class with refactored prototype
CJLucido Sep 19, 2019
f2ab86d
converted CharacterStats to class and refactored its prototype functi…
CJLucido Sep 19, 2019
dcdf6fc
fixed semicolons in constructor functions to commas and converted Hu…
CJLucido Sep 19, 2019
83102e2
Humanoid now extends CharacterStats
CJLucido Sep 19, 2019
cf9ce1b
converted Hero constructor Fn to class with prototype Fn refactored t…
CJLucido Sep 19, 2019
736b0b9
converted Villain from constructor Fn to class, refactored prototype …
CJLucido Sep 19, 2019
56ff4be
created Person class in lambda-classes.js
CJLucido Sep 19, 2019
838a5d5
created a student string at global, created the Instructor class with…
CJLucido Sep 19, 2019
57e3d8f
created a student class that extends person with attributes and methods
CJLucido Sep 19, 2019
895e57a
added this and subject/channel to some of the methods parameters, but…
CJLucido Sep 19, 2019
8bab274
created Project Managers class as extension of Instructors, time to m…
CJLucido Sep 19, 2019
3f42f35
changed Instructor Fn to call a student name and not 'this'
CJLucido Sep 19, 2019
ffbc519
fixed misspelling of Instructor from Instructors in PM extends, remov…
CJLucido Sep 19, 2019
4b157dd
console.logged 3 student methods, all working
CJLucido Sep 19, 2019
e0a514a
retract last comment, listsSubjects is not working. Person method of …
CJLucido Sep 19, 2019
bc4efa3
added Instructor object and tested Instructor methods, both work
CJLucido Sep 19, 2019
b28d3e7
added PM object and tested PM methods, both work. ALMOST MVP at 1hr7min
CJLucido Sep 19, 2019
83ce897
almost fixed listsSubjects using this.favSubjects, returns one subjec…
CJLucido Sep 19, 2019
9e0d571
MVP, baby!
CJLucido Sep 19, 2019
23e8a89
MVP and Stretch!
CJLucido Sep 19, 2019
1ecb46b
2 solutions for listsSubjects and fixes numbering issue
CJLucido Sep 19, 2019
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
118 changes: 118 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,119 @@
// CODE here for your Lambda Classes

let subject = "Mathematics";
let channel = "WEB24";

class Person {
constructor(attr){
this.name = attr.name,
this.age = attr.age,
this.location = attr.location
}

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

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

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

grade(student, subject){
return `${student.name} receives a perfect score on ${subject}`;
}
randomGrade(student){
return `Student's new nonsense score is ${Math.round(Math.random(student.grade) * 100)}`
}
}//end of Instructor class

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

listsSubjects(){//2 answers here

// return this.favSubjects.reduce((acc, currentVal, i) => `${acc}\n${++i}. ${currentVal}`, '').trim();

return `${this.favSubjects.map((currentVal, i) => `\n${i + 1}. ${currentVal}`)}`.trim();

}
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 `Let ${this.name} walk!`
} else {
return `OOF! a ${this.grade}, ${this.name} needs a bit more work!`
}
}
}//end of Student class

class ProjectManager extends Instructor{
constructor(attr){
super(attr);
this.gradClassName = attr.gradClassName,
this.favInstructor
= attr.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}`
}
}//end of PM class

const CJLucido = new Student({
name: "Carlo",
age: "5mil",
location: "THE CENTER OF THE EARTH",
previousBackground: "the rgb code for New Jersey",
className: "Full Stack Web Development",
favSubjects: ["Chi Gong", "Divination", "Yoga"],
grade: 86
});

const BHemm = new Instructor({
name: "Britt",
age: "31",
location: "Toronto",
specialty: "Teaching remotely",
favLanguage: "Kinyarwanda",
catchPhrase: "You better pray for the internet guy too"
})

const Don = new ProjectManager({
name: "Don",
age: "39",
location: "Computer room",
gradClassName: "WEB24",
favInstructor: "Britt",
})
console.log(CJLucido.listsSubjects());
console.log(CJLucido.sprintChallenge(subject));
console.log(CJLucido.PRAssignment(subject));
console.log(CJLucido.speak());
console.log(BHemm.demo(subject));
console.log(BHemm.grade(CJLucido, subject));
console.log(Don.standUp(channel));
console.log(Don.debugsCode(CJLucido, subject));
console.log(BHemm.randomGrade(CJLucido));
console.log(Don.randomGrade(CJLucido));
console.log(CJLucido.graduate(CJLucido));
258 changes: 258 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,261 @@ 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.

*/


/*
=== GameObject ===
* createdAt
* name
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

// function GameObject(props){
// this.createdAt= props.createdAt;
// this.name= props.name;
// this.dimensions = props.dimensions;

// GameObject.prototype.destroy = function(){
// return `${this.name} was removed from the game.`;
// };



// }; //end of GameObject constructor

class GameObject {
constructor(attr){
this.createdAt = attr.createdAt,
this.name = attr.name,
this.dimensions = attr.dimensions
}

destroy(){
return `${this.name} was removed from the game.`;
}
}

// function CharacterStats(stats){
// GameObject.call(this, stats);//inherits from the higher constructor
// this.healthPoints = stats.healthPoints;

// }//end of CharStats constructor

// CharacterStats.prototype = Object.create(GameObject.prototype); //inherits/creates from the higher prototype

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

class CharacterStats extends GameObject{
constructor(attr){
super(attr);
this.healthPoints = attr.healthPoints
}

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


// function Humanoid(traits){
// CharacterStats.call(this, traits);

// this.team = traits.team;
// this.weapons = traits.weapons;
// this.language = traits.language;
// } // end of humanoid constructor


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


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

class Humanoid extends CharacterStats{
constructor(attr){
super(attr);
this.team = attr.team,
this.weapons = attr.weapons,
this.language = attr.language
}

greet(){
return `${this.name} offers a greeting in ${this.language}.`
}
}

// function Hero(virtues){
// Humanoid.call(this, virtues);
// this.divineMight = function(){
// return `${this.name} is immune to plights, makes it rain fire and radioactive light on opponent, destroying all villains`
// };
// }//end of hero constructor

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

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

divineMight(){
return `${this.name} is immune to plights, makes it rain fire and radioactive light on opponent, destroying all villains`
}

}



// function Villain(vices){
// Humanoid.call(this, vices);
// this.unrulyPlight = function(){
// return `A spell spoken in ${this.language} unleashes airbourne flesh eating bacteria, all but heros are taken to near death.`
// };
// }

// Villain.prototype = Object.create(Humanoid.prototype);

class Villain extends Humanoid{
constructor(attr){
super(attr);
}

unrulyPlight(){
return `A spell spoken in ${this.language} unleashes airbourne flesh eating bacteria, all but heros are taken to near death.`
}
}


/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/



/*
=== 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
*/

/*
* 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 paladin = new Hero({
createdAt: new Date(),
dimensions: {
length: 7,
width: 7,
height: 7,
},
healthPoints: 1000,
name: 'Saint',
team: 'Higher Realms',
weapons: [
'Incapatability of presence',
'Sword',
],
language: 'Unknown- Alpha Hz',
});

const demon = new Villain({
createdAt: new Date(),
dimensions: {
length: 6,
width: 6,
height: 6,
},
healthPoints: 1,
name: 'Materiel',
team: 'Denser realms',
weapons: [
'Your vices',
'Guilt',
'Fear',
],
language: 'Low Frequency',
});

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.
console.log(demon.unrulyPlight());
console.log(paladin.divineMight());
console.log(demon.destroy());