From 3bfb63aa86b6f9d92be4f8b1533d65d59d117169 Mon Sep 17 00:00:00 2001 From: munira Date: Wed, 8 Mar 2023 15:32:22 -0600 Subject: [PATCH 1/2] finished prototypes assignment --- classes.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ prototypes.js | 17 ++++++++++++++++- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/classes.js b/classes.js index 5f24389..fe4ba39 100644 --- a/classes.js +++ b/classes.js @@ -36,6 +36,22 @@ console.log("This is example result: ", fred.task()); * dimensions (These represent the character's size in the video game) * destroy() // A method that returns: `${this.name} was removed from the game.` */ +class GameObject{ + constructor(attr){ + this.createdAT = attr.createdAT; + this.dimensions = attr.dimensions; + this.healthPoints = attr.healthPoints; + this.name = attr.name; + this.team = attr.team; + this.weapons = attr.weapons + this.language = attr.language; + } + destroy(){ + return `${this.name} was removed from the game.` + } +} + + /* === CharacterStats === @@ -44,6 +60,16 @@ console.log("This is example result: ", fred.task()); * should inherit destroy() from GameObject's method */ +class CharacterStats extends GameObject{ + constructor(statsAttr){ + super(statsAttr); + } + takeDamage(){ + return `${this.name} took damage.` + } +} + + /* === Humanoid (Having an appearance or character resembling that of a human.) === * team @@ -53,7 +79,18 @@ console.log("This is example result: ", fred.task()); * should inherit destroy() from GameObject through CharacterStats * should inherit takeDamage() from CharacterStats */ - + class Humanoid extends CharacterStats{ + constructor(humaAttr){ + super(humaAttr); + } +greet() { + return `${this.name} offers a greeting in ${this.language}` +} + + } + + + /* * Inheritance chain: GameObject -> CharacterStats -> Humanoid * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. @@ -62,9 +99,9 @@ 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(), + createdAt: new Date("Today's date"), // I tried this to 03/08/2023 dimensions: { length: 2, width: 1, @@ -80,7 +117,7 @@ console.log("This is example result: ", fred.task()); }); const swordsman = new Humanoid({ - createdAt: new Date(), + createdAt: new Date("Today's date"), dimensions: { length: 2, width: 2, @@ -97,7 +134,7 @@ console.log("This is example result: ", fred.task()); }); const archer = new Humanoid({ - createdAt: new Date(), + createdAt: new Date("Today's date"), // I tried this to 03/08/2023 dimensions: { length: 1, width: 2, @@ -123,7 +160,7 @@ console.log("This is example result: ", fred.task()); 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..41289c2 100644 --- a/prototypes.js +++ b/prototypes.js @@ -9,4 +9,19 @@ // 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(greeting,name, age, hobby,){ + this.greeting = greeting; + this.name = name; + this.age = age; + this.hobby = hobby; + +} +Person.prototype.speak = function() { + return `${this.greeting}, my name is ${this.name} and I'm ${this.age} years old. I love ${this.hobby}` +} + +const Me = new Person("hello", "Amina", "20", "football") + +console.log(Me.speak()) \ No newline at end of file From f5e29ef12b09868e85b37bcd583f5449d4b99c11 Mon Sep 17 00:00:00 2001 From: munira Date: Thu, 9 Mar 2023 12:22:00 -0600 Subject: [PATCH 2/2] finished week5 assignment --- classes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes.js b/classes.js index fe4ba39..4139d8a 100644 --- a/classes.js +++ b/classes.js @@ -38,7 +38,7 @@ console.log("This is example result: ", fred.task()); */ class GameObject{ constructor(attr){ - this.createdAT = attr.createdAT; + this.createdAt= attr.createdAt; this.dimensions = attr.dimensions; this.healthPoints = attr.healthPoints; this.name = attr.name; @@ -101,7 +101,7 @@ greet() { const mage = new Humanoid({ - createdAt: new Date("Today's date"), // I tried this to 03/08/2023 + createdAt: new Date("03/09/2023"), // I tried this to 03/08/2023 dimensions: { length: 2, width: 1, @@ -117,7 +117,7 @@ greet() { }); const swordsman = new Humanoid({ - createdAt: new Date("Today's date"), + createdAt: new Date("03/09/2023"), dimensions: { length: 2, width: 2, @@ -134,7 +134,7 @@ greet() { }); const archer = new Humanoid({ - createdAt: new Date("Today's date"), // I tried this to 03/08/2023 + createdAt: new Date("03/09/2023"), // I tried this to 03/08/2023 dimensions: { length: 1, width: 2,