diff --git a/classes.js b/classes.js index 5f24389..18bfe16 100644 --- a/classes.js +++ b/classes.js @@ -28,6 +28,93 @@ console.log("This is example result: ", fred.task()); // ++++ YOUR ASSIGNMENT STARTS HERE +++++ + + +class GameObject{ + constructor(attributes){ + this.createdAt = attributes.createdAt + this.name = attributes.name + + + } + + + destroy() { + return `${this.name} was removed from the game.`; + } +} + +class CharacterStats extends GameObject{ + constructor(attributes){ + super(attributes) + this.healthPoints = attributes.healthPoints + } + + takeDamage() { + return `${this.name} took damage.`; + } +} + +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. /* === GameObject === diff --git a/prototypes.js b/prototypes.js index ddc2e29..b721f3d 100644 --- a/prototypes.js +++ b/prototypes.js @@ -9,4 +9,50 @@ // Move the "Speak" method outside of the constructor function and into the prototype. // Create an object named "Me" using the "Person" constructor function // Call the "Speak" method on the "Me" object -// Console log all your results \ No newline at end of file +// Console log all your results + + + + + +function Person(attr){ + + this.name = attr.name, + this.age = attr.age, + this.hoppy = attr.hoppy + + +} + +Person.prototype.speak = function(){ + return ` magcyku waa ${this.name} waxana ka hilaa ${this.hoppy}` + +} + + +const Me = new Person({ + name : 'xaan', + age : 20, + hoppy : 'fotball' +}) + +console.log(Me.speak()) + + + + +const Prother = new Person({ + name : 'maxmed', + age : 10, + hoppy : 'basketball' +}) + +const Sister = new Person({ + name : 'asmo', + age : 17, + hoppy : 'watching films' +}) + +console.log(Sister.speak()) + +