8000
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
// CODE here for your Lambda Classes | ||
class Person { | ||
constructor(atributes) { | ||
this.name = atributes.name; | ||
this.age = atributes.age; | ||
this.location = atributes.location; | ||
} | ||
speak() { | ||
console.log(`Hello my name is ${this.name}, I am from ${this.location}`); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
class Instructors extends Person { | ||
constructor(instructorAttrs) { | ||
super(instructorAttrs); | ||
this.specialty =instructorAttrs.specialty; | ||
this.favLanguage = instructorAttrs.favLanguage; | ||
this.catchPhrase = instructorAttrs.catchPhrase; | ||
} | ||
demo(subject) { | ||
console.log(`Today we are learning about ${subject}`) | ||
} | ||
grade(student, subject) { | ||
console.log(`${this.name} receives a perfect score on ${subject}`); | ||
} | ||
} | ||
|
||
|
||
|
||
class students extends Person { | ||
constructor(studentAttrs) { | ||
super(studentAttrs); | ||
this.previousBackground = studentAttrs.previousBackground; | ||
this.className = studentAttrs.className; | ||
this.favSubjects = studentAttrs.favSubjects; | ||
|
||
} | ||
listsSubjects() { | ||
console.log(this.favSubjects); //how to log favoriteSubjects one by one | ||
} | ||
PRAssignment(subject) { | ||
console.log(`${this.name} has submitted a PR for ${subject}`); | ||
} | ||
sprintChallenge(subject) { | ||
console.log(`${this.name} has begun sprint challenge on ${subject}`); | ||
} | ||
} | ||
|
||
|
||
|
||
class ProjectManagers extends Instructors { | ||
constructor(pmAttrs) { | ||
super(pmAttrs); | ||
this.gradClassName = pmAttrs.gradClassName; | ||
this.favInstructor = pmAttrs.favInstructor; | ||
} | ||
standUp(channel) { | ||
console.log(`${this.name} announces to ${channel}, @channel standy times!`); | ||
} | ||
debugsCode(student, subject) { | ||
console.log(`${this.name} debugs ${student}'s code on ${subject}`); | ||
} | ||
} | ||
|
||
const fred = new ProjectManagers ({ | ||
name: 'Fred', | ||
location: 'Bedrock', | ||
age: 37, | ||
favLanguage: 'JavaScript', | ||
specialty: 'Front-end', | ||
catchPhrase: `Don't forget the homies`, | ||
gradClassName: 'webPT10', | ||
favInstructor: 'Keiran' | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,148 @@ | ||
/* | ||
|
||
|
||
Prototype Refactor | ||
//Prototype Refactor | ||
|
||
1. Copy and paste your code or the solution from yesterday | ||
// //1. Copy and paste your code or the solution from yesterday | ||
// //GameObject Old code | ||
// 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.`; | ||
// } | ||
|
||
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. | ||
// // GameStats*** Old code | ||
// function CharacterStats(attributes) { | ||
// GameObject.call(this, attributes); | ||
// this.healthPoints = attributes.healthPoints; | ||
// } | ||
// CharacterStats.prototype = Object.create(GameObject.prototype); | ||
|
||
*/ | ||
// CharacterStats.prototype.takeDamage = function takeDamage () { | ||
// return `${this.name} took damage.`; | ||
// } | ||
|
||
|
||
// // Humanoid Old Code *** | ||
// function Humanoid(attributes) { | ||
// CharacterStats.call(this, attributes); | ||
// this.team = attributes.team; | ||
// this.weapons = attributes.weapons; | ||
// this.language = attributes.language; | ||
// } | ||
|
||
// Humanoid.prototype = Object.create(CharacterStats.prototype); | ||
|
||
// Humanoid.prototype.greet = function () { | ||
// return `${this.name} offers a greeting in ${this.language}.` | ||
// } | ||
|
||
|
||
//2. Your goal is to refactor all of this code to use ES6 10000 Classes. The console.log() statements should still return what is expected of them. | ||
//GameObject New code** | ||
|
||
class GameObject { | ||
constructor(attributes) { | ||
this.createdAt = attributes.createdAt; | ||
this.name = attributes.name; | ||
this.dimensions = attributes.dimensions; | ||
} | ||
|
||
destroy() { | ||
console.log(`${this.name} was removed from the game.`); | ||
} | ||
} | ||
|
||
// GameStats New code *** | ||
class CharacterStats extends GameObject { //if doesnt work come back here | ||
constructor(attributes) { | ||
super(attributes); | ||
this.healthPoints = attributes.healthPoints; | ||
} | ||
takeDamage() { | ||
console.log(`${this.name} took damage.`); | ||
} | ||
|
||
} | ||
|
||
|
||
// Humanoid New code *** | ||
class Humanoid extends CharacterStats { | ||
|
||
constructor(attributes) { | ||
super(attributes); | ||
this.team = attributes.team; | ||
this.weapons = attributes.weapons; | ||
this.language = attributes.language; | ||
} | ||
|
||
greet() { | ||
console.log(`${this.name} offers a greeting in ${this.language}.`); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
// Test Code | ||
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', | ||
}); | ||
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. | ||
// | ||
|