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
56 changes: 55 additions & 1 deletion classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,58 @@
// Also give it a method "Speak", which says "Hello, My name is + name + and I'm + age + years old. I love + Hobby"


// Extend Person class and create one class for each member of your family.
// Extend Person class and create one class for each member of your family.


class Person {
constructor(familyMember){
this.name = familyMember.name;
this.Age = familyMember.Age;
this.Hobby = familyMember.Hobby;
}

Speak (){
return `Hello, my name is ${this.name} and I am ${this.Age } years old. I love ${this.Hobby}`
}
}

class Child extends Person{
constructor(children){
super(children)

}
}


const dad = new Person ({
name:'abdi',
Age:46,
Hobby:"Reading Qurran"
});

const FirstSon = new Child ({
name:'Zakaria',
Age:23,
Hobby:"Reading Qurran"
});

const secondSon = new Child ({
name:'abdirashid',
Age:22,
Hobby:"Reading Qurran"
});
const firstDaughter = new Child ({
name:'ayaan',
Age:12,
Hobby:"Reading Qurran"
});






console.log(dad.Speak());
console.log(FirstSon.Speak());
console.log(secondSon.Speak());
console.log(firstDaughter.Speak());
85 changes: 79 additions & 6 deletions prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,51 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/


function GameObject (attributes){

this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.dimensions;



}


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







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


function CharacterStats (charaterAtrbute){
GameObject.call(this, charaterAtrbute);

this.healthPoints= charaterAtrbute.healthPoints;
}


CharacterStats.prototype.takeDamage = function (){
return `${this.name} took damage.`;
}





/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,6 +70,19 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/
function Humanoid (HumanoidAttribute){
CharacterStats.call(this, HumanoidAttribute);

this.team = HumanoidAttribute.team;
this.weapons = HumanoidAttribute.weapons;
this.language = HumanoidAttribute.language;

}

Humanoid.prototype.greet = function(){
return `${this.name} offers a greeting in ${this.language}.`;
}


/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
Expand All @@ -41,7 +92,7 @@

// 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 Down Expand Up @@ -96,15 +147,37 @@
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(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.
*/
console.log(mage.takeDamage()); // Bruce took damage.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.





















// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
// * Create two new objects, one a villain and one a hero and fight it out with methods!
// * Create two new objects, one a villain and one a hero and fight it out with methods!



53 changes: 47 additions & 6 deletions this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
/* The for principles of "this";
/*
The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.


*
* 1.
* 2.
* 3.
* 4.
* 1. Window Binding = "this" keyword tells us where and what it points which is usually being an in the window object.
* 2. Implicit Binding ="look at the left of the dot which calls for the referrence object. 80% usage in the web Devement, and it should use it on objects with methods"
* 3. Explicit Binding = it uses "call" in most cases to connect the two thing, it rarely be used, it immediately and automatically invokes the fucntion. it takes argument.
* 4. new Binding = it uses the "new" keyword and it creates the new object from constructed object and poinst to it.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
function logThis() {
console.log( this)
}


// Principle 2

// code example for Implicit Binding
var myInfo = {
name:"zack",
Age:23,
sayMyInfo: function(){
console.log(this.name);
}
};

myInfo.sayMyInfo();//outpu = "zack"
// Principle 3

// code example for New Binding

function States (name, location){
this.name = name;
this.location =location;

}
const stateOne = new States("ohio", "USA");
console.log(stateOne.location);
console.log(stateOne.name);



// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding

function person (){
console.log(this.name);
}

const personOne = {
name:"abdi"
}


const personTwo = {
name:"mahdi"
}

person.call(personOne)