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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#193407",
"titleBar.activeBackground": "#224909",
"titleBar.activeForeground": "#F4FDEE"
}
}
2 changes: 1 addition & 1 deletion assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

<body>
<h1>JS III - Check your work in the console!</h1>
Expand Down
56 changes: 49 additions & 7 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.
Object oriented design is commonly used in video games.
For this part of the assignment you will be implementing several
constructor functions with their correct inheritance hierarchy.

In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.

At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.
At the bottom of this file are 3 objects that all end up inheriting from Humanoid.
Use the objects at the bottom of the page to test your constructor functions.

Each constructor function has unique properties and methods that are defined in their block comments below:
*/
Expand All @@ -15,6 +18,22 @@
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
*/

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

}

// const block = new GameObject({
// createdAt: 1620,
// dimensions: '3px'
// });

// console.log(block.destroy());

/*
=== CharacterStats ===
* healthPoints
Expand All @@ -23,6 +42,16 @@
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats(characterAttr) {
GameObject.call(this, characterAttr);
this.healthPoints = characterAttr.healthPoints;
this.name = characterAttr.name;
this.takeDamage = function() {
return `${this.name} took damage`;
}

}

/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,6 +61,18 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(humanAttr) {
CharacterStats.call(this,humanAttr);
this.team = humanAttr.team;
this.weapons = humanAttr.weapons;
this.language = humanAttr.language;
this.greet = function() {
return `${this.name} offers a greeting in ${this.language}`;

}

}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
Expand All @@ -41,13 +82,14 @@

// Test you work by un-commenting these 3 objects and the list of console logs below:

/*

// object literal being passed into humanoid
const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
length : 2,
width : 1,
height : 1,
},
healthPoints: 5,
name: 'Bruce',
Expand Down Expand Up @@ -102,7 +144,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
42 changes: 41 additions & 1 deletion assignments/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,54 @@

// code example for Window Binding

console.log(this);

// Principle 2

// code example for Implicit Binding

const human = {
name: 'Larry',
food: "indian food",
cook: function() {
console.log(`${this.name} loves to smash their face into ${this.food}`)
}
}
human.cook();

// Principle 3

// code example for New Binding
function GreetingAlien(name, greeter) {
this.greeter = name;
this.greeter = greeter;
this.greeting = "Hello puny human";
this.speak = function() {
console.log(`${this.greeting}, I am the alient ${this.greeter}`);
}

}
const boiker = new GreetingAlien('Boiker', 'boiker');
const skipo = new GreetingAlien('Skipo', 'Skipo');

// Principle 4

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

const person = {
name: 'Larry'
}

const alien = {
name: 'Spinty'
}

const abilities = ['lazer eyes', 'cold breath', 'programming'];

function introduce() {
// console.log(`Hello my name is ${this.name}, and my abilities are ${abilities[0]}, ${abilities[1]}, ${abilities[2]}`);
console.log(`Hello my name is ${this.name}, and my abilities are ${[...abilities]}`)
// study line ^ spread operator
}

introduce.apply(person, abilities);