diff --git a/classes.js b/classes.js index 5f24389..f077693 100644 --- a/classes.js +++ b/classes.js @@ -28,6 +28,8 @@ console.log("This is example result: ", fred.task()); // ++++ YOUR ASSIGNMENT STARTS HERE +++++ + + /* === GameObject === @@ -37,6 +39,21 @@ console.log("This is example result: ", fred.task()); * destroy() // A method that returns: `${this.name} was removed from the game.` */ +class GameObject{ + constructor(attributes){ + this.createdAt =attributes.createdAt; + this.name = attributes.name; + this.demensions =attributes.demensions; + + } +destory(){ + return `${this.name} was removed from the game.` +} +} +const swordsman = new GameObject({ + name: "Sir Mustachio" +}) +console.log(swordsman.destory()) /* === CharacterStats === * healthPoints @@ -44,6 +61,20 @@ console.log("This is example result: ", fred.task()); * should inherit destroy() from GameObject's method */ + +class CharacterStats extends GameObject { + constructor(characterstartsAttributes){ + super(characterstartsAttributes) + this.name = characterstartsAttributes.name; + } +takeDamage(){ + return `${this.name} took damage` +} +} + const mage = new CharacterStats({ name:"Bruce" +}) + + console.log(mage.takeDamage()) /* === Humanoid (Having an appearance or character resembling that of a human.) === * team @@ -54,6 +85,25 @@ console.log("This is example result: ", fred.task()); * should inherit takeDamage() from CharacterStats */ +class Humanoid{ + constructor(attributes){ + this.team = attributes.team; + this.weapons = attributes.weapons; + this.languege = attributes.languege; + this.name = attributes.name + } + greet(){ + return `${this.name} a greating in ${this.languege}` + } +} + +const archer = new Humanoid({ + name:"Lilith", + languege: "Elvish" +}) + +// console.log(archer.greet()) + /* * Inheritance chain: GameObject -> CharacterStats -> Humanoid * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. @@ -62,68 +112,68 @@ console.log("This is example result: ", fred.task()); // 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', - }); - - 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. -*/ + + // 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. + // Stretch task: // * Create Villain and Hero class that inherit from the Humanoid class. diff --git a/prototypes.js b/prototypes.js index ddc2e29..d3fcde2 100644 --- a/prototypes.js +++ b/prototypes.js @@ -5,6 +5,23 @@ // Give it "Name", "Age", "Hobby" properties // Also give it a method "Speak", which says "Hello, My name is + name + and I'm + age + years old. I love + Hobby" +function Person(attr){ + this.name = attr.name; + this.age = attr.age; + this.hobby = attr.hobby; + +} + +Person.prototype.speak = function(){ + return `hello, my name is ${this.name} and iam ${this.age} years old. i love ${this.hobby} ` + } + + +const Me = new Person ("Ayan",'20', 'foodball' ) + +console.log(Me.speak()) + + // Move the "Speak" method outside of the constructor function and into the prototype. // Create an object named "Me" using the "Person" constructor function