Skip to content

changed js files code runs now #2

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 5 commits 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
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
}
40 changes: 24 additions & 16 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ function GameObject(attribute) {
this.createdAt = attribute.createdAt;
this.name = attribute.name;
this.dimensions = attribute.dimensions;
this.destroy = function(){
return `${this.name} was removed from the game`;
}


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

}
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(attribute) {
this.healthPoints = attribute.healthPoints;
this.takeDamage = function() {
return `${attribute.name} took damage`
}
GameObject.call(this, attribute);

this.healthPoints = attribute.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 @@ -49,16 +55,18 @@ function CharacterStats(attribute) {
* should inherit takeDamage() from CharacterStats
*/
function Humanoid(attribute) {

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

}
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 Down
43 changes: 26 additions & 17 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1. in a global scope this is refering to the window or console object
* 2. implicit binding is refering to the object you are currently working on
* 3. when using a new constuctor binding the this keyword is refering to the object being created and returned
* 4. in explicit binding the this keyword is defined directly
* 1. The keyword This on a global scope refers to the window or console object
* 2. The keyword This in implicit binding refers to the object to left of the kewword This.
* 3. The keyword This when used with the keyword New in a constuctor binding refers to the object being created and returned
* 4. The keyword this in explicit binding refers to the parameter being added.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
function sayHi(greeting) {
console.log(this);
return greeting;
}
sayHi("Hello")
console.log(this)

// Principle 2

// code example for Implicit Binding
const person = {
name: "John",
sayName: function(name) {
sayName: function() {
console.log(`${this.name}`);
console.log(this);
}
}
person.sayName();
Expand All @@ -37,14 +32,28 @@ function MorningGreeting(person) {
this.greeter = person;
this.tell = function() {
console.log(`${this.greeting} ${this.greeter}`);
console.log(this);

}
}
const maria = new MorningGreeting("Maria");
console.log(maria.tell());
const goodMorningMaria = new MorningGreeting("Maria");
goodMorningMaria.tell()
console.log(goodMorningMaria)

// Principle 4

// code example for Explicit Binding
const kim = new MorningGreeting("Kim")
console.log(kim.tell.call(maria));
console.log(kim.tell());
function chores(person) {
console.log(`It's ${this.name}'s turn to do the ${this.chore}`)
}

const kid1 = {
name: "Tim",
chore: "dishes"
}

const kid2 = {
name: "Mary",
chore: "mopping"
}
chores.call(kid1);
chores.call(kid2)