diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..5dee03cf8 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,22 @@ // CODE here for your Lambda Classes +class Person { + constructor(personAttr){ + this.name = personAttr.name; + this.age = personAttr.age; + this.location = personAttr.location; + this.gender = personAttr.gender; + } + + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}`; + } +}; + +const Fred = new Person({ + name: 'Fred', + location: 'Bedrock', + age: 37, + gender: 'male', + }); + + console.log(fred.speak()); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..cce3bffd0 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,53 @@ // 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. -function GameObject(options) { +class GameObject { + + constructor(options) { + this.createdAt = options.createdAt; this.dimensions = options.dimensions; -} + //this.name = options.dimentions; -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; + } + destroy() { + return `${this.name} was removed from the game.`; + +} }; -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); + class CharacterStats extends GameObject { + constructor(characterStatsOptions){ + super(characterStatsOptions); this.hp = characterStatsOptions.hp; this.name = characterStatsOptions.name; } -CharacterStats.prototype = Object.create(GameObject.prototype); -CharacterStats.prototype.takeDamage = function() { + takeDamage() { return `${this.name} took damage.`; -}; +} + +} + -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); + class Humanoid extends CharacterStats { + constructor(humanoidOptions){ + super(humanoidOptions); this.faction = humanoidOptions.faction; this.weapons = humanoidOptions.weapons; this.language = humanoidOptions.language; + } + + greet() { + return `${this.name} offers a greeting in ${this.language}.`; + }; + } -Humanoid.prototype = Object.create(CharacterStats.prototype); -Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; -}; + + const mage = new Humanoid({ createdAt: new Date(),