Skip to content

finished MVP #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/JS-III.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>JS III</title>

<script src="this.js"></script>
<script src="prototypes.js"></script>
<!-- <script src="prototypes.js"></script>-->
</head>

<body>
Expand Down
33 changes: 29 additions & 4 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 (objAttributes) {
this.createdAt = objAttributes.createdAt;
this.name = objAttributes.name;
this.dimensions = objAttributes.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(charAttributes) {
GameObject.call(this, charAttributes);
this.healthPoints = charAttributes.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) {
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,6 @@

// 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 +127,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
38 changes: 29 additions & 9 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
/* 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 - When in the global scope, the value of “this” will be the window/console Object
* 2. Implicit Binding - Whenever a function is called by a preceding dot, the object before that dot is this
* 3. New Binding - Whenever a constructor function is used, this refers to the specific instance of the object that is created and returned by the constructor function
* 4. Explicit Binding - Whenever JavaScript’s call or apply method is used, this is explicitly defined
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
console.log(this);

// Principle 2

// code example for Implicit Binding
let theGuy = {
name: 'Guy',
isAction: function (action) {
console.log(`${this.name} is ${action}.`)
}
};
theGuy.isAction('walking');

// Principle 3

// code example for New Binding
function Me(attr) {
this.name = attr.name;
this.whoIam = function () {
console.log(`${this.name}'s job is hard.`);
};
}
let mike = new Me({
name: 'Mikey',
});
let john = new Me({
name: 'John',
});
mike.whoIam();
john.whoIam();

// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
john.whoIam.call(mike);
mike.whoIam.call(john);