Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 62 additions & 16 deletions classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +++++

Expand All @@ -37,13 +37,46 @@ 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.dimensions = attributes.dimensions;

}

destroy() {
return `${this.name} was removed from the game`;
}

}



/*
=== CharacterStats ===
* healthPoints
* takeDamage() // A method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's method
*/


class CharacterStats extends GameObject {
constructor(attributes){
super(attributes);
this.healthPoints = attributes.healthPoints;

}
takeDamage(){
return `${this.name} took damage`;
}



}


/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -53,6 +86,20 @@ 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(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
Expand All @@ -62,7 +109,7 @@ 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: {
Expand All @@ -75,8 +122,7 @@ console.log("This is example result: ", fred.task());
team: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
], language: 'Common Tongue',
});

const swordsman = new Humanoid({
Expand Down Expand Up @@ -123,7 +169,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.
Expand Down
25 changes: 25 additions & 0 deletions prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down