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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
32 changes: 29 additions & 3 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@
* dimensions (These represent the character's size in the video game)
* 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(childAttributes) {
GameObject.call(this, childAttributes);
this.healthPoints = childAttributes.healthPoints;
}

CharacterStats.prototype = Object.create(GameObject.prototype);
CharacterStats.prototype.takeDamage = function(){
return `${this.name} took damage.`;
}
/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,7 +48,17 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(humanAttributes) {
GameObject.call(this, humanAttributes);
CharacterStats.call(this, humanAttributes);
this.team = humanAttributes.team;
this.weapons = humanAttributes.weapons;
this.language = humanAttributes.language;
}
Humanoid.prototype = Object.create(CharacterStats.prototype);
Humanoid.prototype.greet = function () {
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.
Expand All @@ -41,7 +67,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 @@ -102,7 +128,7 @@
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 constructor functions that inherit from the Humanoid constructor function.
Expand Down
43 changes: 37 additions & 6 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. When a function is contained in global scope the value of this inside that function will be the window object.
* 2. Everything to the left of the dot in a function is what this is refering too
* 3. When you call an object it will immediatley invoke the function
* 4. New binding you create a new keyword for a new object and points to it.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding

function sayAge () {
console.log(`My age is ${this.age}`)
}

const user = {
name: "Farid",
age:25
}
sayAge();
// Principle 2

// code example for Implicit Binding
let myCat = {
name: "Meowth",
speech: "English",
cat: function () {
console.log(this.speech);
}
}
myCat.cat();

// Principle 3

// code example for New Binding
function Dog(saying) {
this.phase = saying;
}

let myDog = new Dog("Woof Woof");

console.log(myDog.phase);
// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
function pokemon() {
console.log(this.type);
}

let myPokemon = {
name: "Charmander",
type: "Fire",
}
pokemon.call(myPokemon);