From b2f17c201aa96a3e714e035fd43421b2eef48e98 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Nov 2022 22:14:58 -0700 Subject: [PATCH 1/3] first-commit --- classes.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/classes.js b/classes.js index 5f24389..4bc69fd 100644 --- a/classes.js +++ b/classes.js @@ -37,6 +37,36 @@ 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.createdAd = attributes.createdAd; + this.name = attributes.name; + this.dimentions = attributes.dimentions; + + } + + destroy() { + return `${this.name} was removed from the game` + } + +} + +const swordsman= new GameObject ({ + name: mastachio, + createdAd: new Date(), + dimentions: { + lenght: 2, + width: 1, + height: 1, + }, + + + +}) + + console.log("swordsman.name", destroy()); + /* === CharacterStats === * healthPoints @@ -44,6 +74,17 @@ console.log("This is example result: ", fred.task()); * should inherit destroy() from GameObject's method */ + + class CharacterStats extends GameObject { + constructor(attributes){ + super(attributes){ + this. + } + } + + } + + /* === Humanoid (Having an appearance or character resembling that of a human.) === * team From 87ea766f65268449ef42d2648db1f81a1e055f84 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Nov 2022 04:38:45 -0700 Subject: [PATCH 2/3] second-commit --- classes.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/classes.js b/classes.js index 4bc69fd..3da4c4e 100644 --- a/classes.js +++ b/classes.js @@ -47,7 +47,7 @@ class GameObject { } destroy() { - return `${this.name} was removed from the game` + return `${this.name} was removed from the game`; } } @@ -77,13 +77,29 @@ const swordsman= new GameObject ({ class CharacterStats extends GameObject { constructor(attributes){ - super(attributes){ - this. - } + super(attributes); + this.healthPoints = attributes.healthPoints; + } + takede(){ + return `${this.name} bruce took damage`; + } + + - } + } + + + const mage = new CharacterStats({ + name: "bruce", + healthPoints: 5, + team: " Mage Guild", + weapons: [ + "Staff of Shamalma" + ], + language : "Common Tongue", + }); /* === Humanoid (Having an appearance or character resembling that of a human.) === @@ -116,8 +132,7 @@ const swordsman= new GameObject ({ team: 'Mage Guild', weapons: [ 'Staff of Shamalama', - ], - language: 'Common Tongue', + ], language: 'Common Tongue', }); const swordsman = new Humanoid({ @@ -144,7 +159,7 @@ const swordsman= new GameObject ({ width: 2, height: 4, }, - healthPoints: 10, + healthPoints: 10,----------------------- name: 'Lilith', team: 'Forest Kingdom', weapons: [ From ef8ad111e935486f8d7c79d8da0cbe54088c304b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Nov 2022 18:22:03 -0700 Subject: [PATCH 3/3] last-commit --- classes.js | 76 ++++++++++++++++++++++----------------------------- prototypes.js | 25 +++++++++++++++++ 2 files changed, 58 insertions(+), 43 deletions(-) diff --git a/classes.js b/classes.js index 3da4c4e..acf3bb1 100644 --- a/classes.js +++ b/classes.js @@ -10,21 +10,21 @@ // ++++ Example Class +++++ -class Employee{ - constructor(attributes) { - this.name = attributes.name; - } +// class Employee{ +// constructor(attributes) { +// this.name = attributes.name; +// } - task() { - return `${this.name} is working on a task.`; - } -} +// task() { +// return `${this.name} is working on a task.`; +// } +// } -const fred = new Employee({ - name: 'Fred', -}); +// const fred = new Employee({ +// name: 'Fred', +// }); -console.log("This is example result: ", fred.task()); +// console.log("This is example result: ", fred.task()); // ++++ YOUR ASSIGNMENT STARTS HERE +++++ @@ -40,9 +40,9 @@ console.log("This is example result: ", fred.task()); class GameObject { constructor(attributes) { - this.createdAd = attributes.createdAd; + this.createdAt= attributes.createdAt; this.name = attributes.name; - this.dimentions = attributes.dimentions; + this.dimensions = attributes.dimensions; } @@ -52,21 +52,8 @@ class GameObject { } -const swordsman= new GameObject ({ - name: mastachio, - createdAd: new Date(), - dimentions: { - lenght: 2, - width: 1, - height: 1, - }, - -}) - - console.log("swordsman.name", destroy()); - /* === CharacterStats === * healthPoints @@ -81,8 +68,8 @@ const swordsman= new GameObject ({ this.healthPoints = attributes.healthPoints; } - takede(){ - return `${this.name} bruce took damage`; + takeDamage(){ + return `${this.name} took damage`; } @@ -90,17 +77,6 @@ const swordsman= new GameObject ({ } - const mage = new CharacterStats({ - - name: "bruce", - healthPoints: 5, - team: " Mage Guild", - weapons: [ - "Staff of Shamalma" - ], - language : "Common Tongue", - }); - /* === Humanoid (Having an appearance or character resembling that of a human.) === * team @@ -110,6 +86,20 @@ const swordsman= new GameObject ({ * should inherit destroy() from GameObject through CharacterStats * should inherit takeDamage() from CharacterStats */ + + class Humanoid extends CharacterStats{ + constructor(attributes){ + super(attributes); + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + + + greet(){ + return ` ${this.name} offers a greening in ${this.language}`; + } + } /* * Inheritance chain: GameObject -> CharacterStats -> Humanoid @@ -119,7 +109,7 @@ const swordsman= new GameObject ({ // Test you work by un-commenting these 3 objects and the list of console logs below: -/* + const mage = new Humanoid({ createdAt: new Date(), dimensions: { @@ -159,7 +149,7 @@ const swordsman= new GameObject ({ width: 2, height: 4, }, - healthPoints: 10,----------------------- + healthPoints: 10, name: 'Lilith', team: 'Forest Kingdom', weapons: [ @@ -179,7 +169,7 @@ const swordsman= new GameObject ({ 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..d862918 100644 --- a/prototypes.js +++ b/prototypes.js @@ -5,6 +5,31 @@ // 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(attributes){ +this.age = attributes.age; +this.name = attributes.name; +this.hubby =attributes.hubby; +// this.speak = functon(){ +// return `"Hello, My name is + name + and I'm + age + years old. I love + Hobby"`; +}; + +Person.prototype.speak = function() { + + return `Hello, My name is ${this.name} and I'm ${this.age} age years old. i love ${this.hubby} Hobby`; +}; + + + + + const me = new Person({ + name: "mohamed", + age: 38, + hubby: "coding", + + }) + + + 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