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

class Instructor extends Person {
constructor (instructorParams) {
super(instructorParams) ;
this.specialty = instructorParams.specialty ;
this.favLanguage = instructorParams.favLanguage ;
this.catchPhrase = instructorParams.catchPhrase ;
}
demo(subject){
console.log (`Today we are learning about ${subject}!`) ;
}
grade(student, subject){
console.log (`${student.name} receives a perfect score on ${subject}.`) ;
}
/* strech */
applyGrade(student){
let newGrade = student.grade ;
let randomGrade = Math.floor(Math.random()*100) ;
let negOrPosNum = Math.random() < 0.5 ? -1 : 1 ;
newGrade = newGrade + (randomGrade * negOrPosNum) ;
if (newGrade >= 100){
return student.grade = 100 ;
}else if(newGrade < 0){
return student.grade = 0 ;
}else{
return student.grade = newGrade ;
}
}
}

class Student extends Person {
constructor (studentParams) {
super(studentParams) ;
this.previousBackground = studentParams.previousBackground ;
this.className = studentParams.className ;
this.favSubjects = studentParams.favSubjects ;
/* strech */
this.grade = studentParams.grade;
}

listsSubjects(){

let newArr = [];

for(let i=0; i < this.favSubjects.length; i++){
newArr.push(this.favSubjects[i]) ;
}
console.log(`${this.name}s favourite subjects are ${newArr}`) ;

return newArr ;
}

PRAssignment(subject)
{
console.log((`${this.name} has submitted a PR for ${subject}!`)) ;
}
sprintChallenge(subject){
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}
/* strech */
graduate(student){
if (this.grade > 70){
console.log(`${this.name} is cleared for takeoff!`) ;
}else {
console.log(`Back to the drawing board!`) ;
}
}
}

class PM extends Instructor {
constructor(pmParams){
super(pmParams) ;
this.gradClassName = pmParams.gradClassName ;
this.gradClassName = pmParams.favInstructor ;
}
standUp(slackChannel){
console.log(`${this.name} announces to ${slackChannel}, @channel standy times!​​​​​`) ;
}
debugsCode(student, subject){
console.log(`${this.name} debugs ${student.name}'s code on ${subject}`) ;
}
}
const tristan = new Student({
//props from parent
name: 'Tristan',
age: 34,
gender: true,
//props from child
favSubjects: ['html', 'css', 'js']
});
const haywood = new PM({
name: 'Haywood'
});
const josh = new Instructor ({
catchPhrase: 'deep dive'
})
tristan.listsSubjects();//?
const randomValueInArray = function (array) {
return array[Math.floor(Math.random()*array.length)] ;//?
}
tristan.PRAssignment(randomValueInArray(tristan.favSubjects))//*?
tristan.sprintChallenge('excellence');//*?
haywood.debugsCode(tristan,'javaScript'); //*?
josh.demo(josh.catchPhrase);//*?

/* strech */
tristan.grade = 85;
console.log(josh.applyGrade(tristan));//*?
tristan//?
tristan.graduate();//*?

45 changes: 45 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.

/*//PROTOTYPE INHERITANCE - COMMITED OUT
function GameObject(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
Expand All @@ -10,7 +11,20 @@ function GameObject(options) {
GameObject.prototype.destroy = function() {
return `Object was removed from the game.`;
};
*/

//CLASS CONTRUCTOR ES6
//BASE (PARENT) CLASS
class GameObject {
constructor (parentParams) {
this.createdAt = parentParams.createdAt ;
this.dimensions = parentParams.dimensions ;
}
destroy() {
return `${this.name} was removed from the game!` ;//?
}
}
/*
function CharacterStats(characterStatsOptions) {
GameObject.call(this, characterStatsOptions);
this.hp = characterStatsOptions.hp;
Expand All @@ -22,7 +36,24 @@ CharacterStats.prototype = Object.create(GameObject.prototype);
CharacterStats.prototype.takeDamage = function() {
return `${this.name} took damage.`;
};
*/

//CHILD CLASS BELOW
////'EXTENDS' (creates a child)
//NOTE SYNTAX: class child EXTENDS parent
class CharacterStats extends GameObject {
constructor (childParams) {
//'SUPER' KEYWORD IS USED TO ACCESS AND CALL FUNCTIONS ON AN OBJECTS PARENT​​​​​
super(childParams) ;

this.hp = childParams.hp ;
this.name = childParams.name
}
takeDamage() {
return `${this.name} took damage.` ;
}
}
/*
function Humanoid(humanoidOptions) {
CharacterStats.call(this, humanoidOptions);
this.faction = humanoidOptions.faction;
Expand All @@ -35,6 +66,20 @@ Humanoid.prototype = Object.create(CharacterStats.prototype);
Humanoid.prototype.greet = function() {
return `${this.name} offers a greeting in ${this.language}.`;
};
*/
class Humanoid extends CharacterStats {
constructor (grandChildParams) {
super(grandChildParams) ;
this.faction = grandChildParams.faction ;
this.weapons = grandChildParams.weapons ;
this.language = grandChildParams.language ;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.` ;
}
}

////END OF MY CODE

const mage = new Humanoid({
createdAt: new Date(),
Expand Down