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 assignments/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
3 changes: 2 additions & 1 deletion assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</head>

<body>
<h1>JS III - Check your work in the console!</h1>
<h1>Spencers
JS III - Check your work in the console!</h1>
</body>
</html>
82 changes: 78 additions & 4 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,36 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function GameObject(attrs){
this.createdAt = attrs.createdAt;
this.name = attrs.name;
this.dimensions = attrs.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(stats){
GameObject.call(this, stats);

this.healthPoints = stats.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.) ===
Expand All @@ -32,7 +56,18 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(chara){
CharacterStats.call(this, chara)
this.team = chara.team;
this.weapons = chara.weapons;
this.language = chara.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 +76,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,9 +137,48 @@
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.
// * 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!

const hero = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 2,
height: 2,
},
healthPoints: 10,
name: 'Bean',
team: 'Bean Plant',
weapons: [
'holy bean',
],
language: 'beanish',
});

const villain = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 10,
width: 2,
height: 2,
},
healthPoints: 10,
name: 'snek',
team: 'slithers',
weapons: [
'venom',
],
language: 'parcel tounge',
});

function fight(points){
this.dmg = points.dmg;
this.hp = points.hp;
}

// finish @ luch
43 changes: 31 additions & 12 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
1. Window/Global Binding - 'this' keyword defaults to the entire window as an object
* 2. Implicit binding - 'this' keyword is automatically bound to object method. Occurs when dot notation is used on a call a function.
* 3. Explicit binding - 'this' keyword is explicitly stated what certain value it is pointed to using .call(), .apply(), .bind() on a function.
* 4. 'new' binding - using 'new' keyword constructs a new object and 'this' points to the new object.
*
*
* write out a code example of each explanation above
*/

// Principle 1
// Principle 1 global

function sayBean(bean) {
console.log(bean);
}
sayBean("A bean has bean said");

// code example for Window Binding
// Principle 2 implicit
const wow = {
wowman: 'Owen Wilson',
wowza: function(word){
console.log(`click here to watch ${this.wowman} say ${word} in a 24hr loop`)
}
};
wow.wowza('WOW')

// Principle 2
// Principle 3 new

// code example for Implicit Binding
function BeanPerson(greeter) {
this.word = 'henlo';
this.greeter = greeter;
this.speaker = function(){
console.log(`${this.word} fellow ${this.greeter}`)
};
}

// Principle 3
const beano = new BeanPerson('Bean Person')

// code example for New Binding
beano.speaker();

// Principle 4
// Principle 4 explict

// code example for Explicit Binding
// Prototype.js used explicit binding alot - like when we made new methods and passed the attributes of the old method in using method.call(another method)