diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..a76f1bea0 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,126 @@ // CODE here for your Lambda Classes + +// Base CLASS -- parent +class Person { + constructor(attrs) { + this.name = attrs.name; + this.age = attrs.age; + this.location = attrs.location; + } + // Methods: + speak() { + console.log(`Hello my name is ${this.name}, I am from ${this.location}`); + } +} + +// Instructor CLASS -- chiled + +class Instructor extends Person { + constructor(attrs) { + super(attrs); + this.specialty = attrs.specialty; + this.favLanguage = attrs.favLanguage; + this.catchPhrase = attrs.catchPhrase; + } + // Methods: + demo(subject) { + console.log(`Today we are learning about ${subject}`); + } + grade(student, subject) { + console.log(`${student.name} receives a perfect score on ${subject}`); + } + subtractPoints(student, subject, grade) { + console.log(`${student} grade in ${subject}: `); + console.log(`Student grade: ${grade} - New Student grade: ${grade - Math.random()}`); + } + addPoints(student, subject, grade) { + console.log(`${student} grade in ${subject}: `); + let newGrade = grade + Math.random(); + console.log(`Student grade: ${grade} - New Student grade: ${newGrade}`); + } +} + +// Student CLASS -- chiled + +class Student extends Person { + constructor(attrs) { + super(attrs); + this.previousBackground = attrs.previousBackground; + this.className = attrs.className; + this.grade = attrs.grade; + this.fafavSubjects = attrs.favSubjects; + } + // Methods: + listsSubjects(fafavSubjects) { + console.log(`Hello my name is ${jane.name}. My favorite subjects are: `); + for (let i = 0; i < fafavSubjects.length; i++) { + console.log(`subject # ${i + 1}: ${fafavSubjects[i]}`); // prints out an array + } + } + PRAssignment(subject) { + console.log(`${this.name} has submitted a PR for ${subject}`); + } + sprintChallenge(subject) { + console.log(`${this.name} has begun sprint challenge on ${subject}`); + } +} + +// Project Manager CLASS -- chiled + +class ProjectManager extends Instructor { + constructor(attrs) { + super(attrs); + this.gradClassName = attrs.gradClassName; + this.favInstructor = attrs.favInstructor; + } + // Methods: + standUp(channel) { + console.log(`${this.name} announces to ${channel}, @channel standy times!​​​​​`); + } + debugsCode(studentObj, subject) { + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`); + } +} + + + +// Calling action: +const fred = new Instructor ({ + name: 'Fred', + location: 'Bedrock', + age: 37, + favLanguage: 'JavaScript', + specialty: 'Back-end', + catchPhrase: `Don't forget the homies`, +}); + +const jane = new Student ({ + name: 'Jane', + location: 'Verginia', + age: 25, + previousBackground: 'Teacher', + className: 'WEBPT11', + grade: 87, + favSubjects: ['Html', 'CSS', 'JavaScript'], +}); + +const eric = new ProjectManager ({ + name: 'Eric', + location: 'Colorado', + age: 30, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `say what`, + gradClassName: 'WEBPT11', + favInstructor: 'Fred', +}); + + +console.log(jane.listsSubjects(jane.fafavSubjects)); +console.log(jane.grade); +console.log(fred.specialty); +console.log(fred.demo(`JavaScript - IV`)); +console.log(fred.subtractPoints(jane.name, `JavaScript - IV`, jane.grade)); +console.log(fred.addPoints(jane.name, `JavaScript - IV`, jane.grade)); + + diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..ad117b048 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,233 @@ 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 === + +// function GameObject(attributes){ +// this.createdAt = attributes.createdAt; +// this.name = attributes.name; +// this.dimensions = attributes.dimensions; +// } +// GameObject.prototype.destroy = function() { +// return `${this.name} was removed from the game.`; +// } + +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.`; + } +} + +// === CharacterStats === + +// function CharacterStats(charAttributes) { +// GameObject.call(this, charAttributes); +// this.healthPoints = charAttributes.healthPoints; +// } + +// CharacterStats.prototype = Object.create(GameObject.prototype); + +// CharacterStats.prototype.takeDamage = function() { +// return `${this.name} took damage.` +// } + +class CharacterStats extends GameObject { + constructor(charAttributes) { + super(charAttributes); + this.healthPoints = charAttributes.healthPoints; + } + takeDamage() { + return `${this.name} took damage.` + } +} + +// === Humanoid (Having an appearance or character resembling that of a human.) === + +// function Humanoid(humanAttributes) { +// CharacterStats.call(this, humanAttributes); +// this.team = humanAttributes.team; +// this.weapons = humanAttributes.weapons; +// this.language = humanAttributes.language; +// } + +// Humanoid.prototype = Object.create(CharacterStats.prototype); + +// Humanoid.prototype.greet = function() { +// return `${this.name} offers a greeting in ${this.language}.` +// } + +class Humanoid extends CharacterStats { + constructor(humanAttributes) { + super(humanAttributes); + this.team = humanAttributes.team; + this.weapons = humanAttributes.weapons; + this.language = humanAttributes.language; + this.V_newhealthPoints = humanAttributes.healthPoints - 5; + this.H_newhealthPoints = this.V_newhealthPoints + 1; + this.Total_healthPoints = this.H_newhealthPoints; + } + greet() { + return `${this.name} offers a greeting in ${this.language}.` + } +} + +// === Stretch task: === + +// function Villain(villainAttributes) { +// Humanoid.call(this, villainAttributes); +// this.deception = villainAttributes.deception; +// this.poison = villainAttributes.poison; +// } + +// Villain.prototype = Object.create(Humanoid.prototype); + +// Villain.prototype.stabBack = function() { +// return `Plot twist! ${this.name} has just deceived you!` +// } + +// function Hero (heroAttributes) { +// Humanoid.call(this, heroAttributes); +// this.truth = heroAttributes.truth; +// this.strength = heroAttributes.strength; +// } + +// Hero.prototype = Object.create(Humanoid.prototype); + +// Hero.prototype.attack = function() { +// return `${this.name} the hero will win in the end.` +// } + +class Villain extends Humanoid { + constructor(villainAttributes) { + super(villainAttributes); + this.deception = villainAttributes.deception; + this.poison = villainAttributes.poison; + // this.V_newhealthPoints = Son.healthPoints - 5; + } + stabBack() { + // let newhealthPoints = Son.healthPoints - 5; + console.log(`Plot twist! ${this.name} The Father has just deceived The Hero (aka The Son)!`) + console.log(`${Son.name} initial health points: ${Son.healthPoints} -- new health points total: ${Son.V_newhealthPoints}.`); + } +} + +class Hero extends Humanoid { + constructor(heroAttributes) { + super(heroAttributes); + this.truth = heroAttributes.truth; + this.strength = heroAttributes.strength; + } + attack() { + // let newhealthPoints = this.healthPoints + 1; + console.log(`${this.name} is the hero they win in the end.`); + console.log(`${this.name} initial health points: ${Son.V_newhealthPoints} -- new health points total: ${Son.H_newhealthPoints}.`); + } +} + +// 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', + deception: 'You have just been deceived.', +}); + +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', +}); + +// Stretch task: + +const Father = new Villain ({ + name: 'Sir Mustachio', + deception: 'You have just been deceived.', + poison: -1, + truth: 'The truth will guide you', + strength: 20, +}); + +const Son = new Hero ({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + healthPoints: 10, + name: 'Lilith', + team: 'Forest Kingdom', + weapons: [ + 'Bow', + 'Dagger', + ], + language: 'Elvish', + deception: 'You have just been deceived.', + poison: -1, + truth: 'The truth will guide you', + strength: 20, +}); + +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(Father.stabBack()); // Health Points - 5 +console.log(Son.attack()); // Health Points + 1 +// console.log(Father.stabBack()); // Health Points - 5 \ No newline at end of file diff --git a/assignments/tempCodeRunnerFile.js b/assignments/tempCodeRunnerFile.js new file mode 100644 index 000000000..453c01b49 --- /dev/null +++ b/assignments/tempCodeRunnerFile.js @@ -0,0 +1 @@ +console.log(Father.stabBack()); // Health Points - 5 \ No newline at end of file