Skip to content
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

Javascript II Mini #79

Open
wants to merge 2 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
13 changes: 12 additions & 1 deletion classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

// problem #1
// convert the Animal constructor function from 'constructors.js' into an ES6 class
class classAnimal {
Animal(options) {
this.name = options.name;
this.grow=options.grow;
}
}


// problem #2
// convert the Cat constructor function from 'constructors.js' into an ES6 class
class classCat extends classAnimal {
Cat(options) {
super(options)
this.isclassCat = options.isclassCat;
}
}


// if everything is setup properly the code below will print 'Foofie grew larger!'
Expand All @@ -16,4 +28,3 @@
// });
//
// foofie.grow();

9 changes: 8 additions & 1 deletion constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

function Animal(options) {
this.name = options.name;
this.grow=options.grow;
}

Animal.prototype.grow = function {
return `${this.name} grew larger!`;
}

// add 'grow' to Animal's prototype here
grow.prototype.Object.create(Animal.prototype);

// problem #2
// setup Cat to inherit from Animal
Expand All @@ -18,6 +24,8 @@ function Animal(options) {

function Cat(options) {
// invoke Animal here with .call
Animal.call(options);
this.grow = options.grow;
}

// connect the prototypes here
Expand All @@ -30,4 +38,3 @@ function Cat(options) {
// });
//
// foofie.grow();

13 changes: 12 additions & 1 deletion recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ while (n <= 10) {
// write a recursive - function called countToTen that mimics the while loop above.

// code here
const countToTen = (n) => {
if (n <= 10) return;
console.log('While Loop', n);
countToTen(n+1);

};
countToTen()

// when you code is ready, un-comment the next line and run the file
// console.log(countToTen());
console.log(countToTen());
/* ================ Next Problem ================= */

// Problem 2:
Expand All @@ -28,6 +35,10 @@ const factorial = n => {
console.log(factorial(5));

// write the above function in a recursive way.
const factorial = (n) => {
if (n===1) return 1;
return n * factorial
}

// when your code is ready, un-comment the next line and run the file
// console.log(recursiveFactorial());
48 changes: 43 additions & 5 deletions this.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* The for principles of "this";
* 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-information from whatever console you are using
* 2. Implicit Binding-the object before dot, thats the this(what its referring to)
* 3. New Biding-function that creates an object then returns it
* 4. Explicit Binding-overide what objects get set to with .call and .apply
*
* write out a code example of each explanation above
*/
Expand All @@ -14,15 +14,53 @@ console.log('hello world!');
// Principle 1

// code example for Window Binding
function winBind(name) {
return name;
}
winBit('Kelly')

// Principle 2

// code example for Implicit Binding
const myTown = {
weather: 'rain',
mood: 'relaxed'
myAtmosphere: function(weather) {
console.log(this.mood)
}
}
myTown.myAtmosphere();

// Principle 3

// code example for New Binding
const myTown = {
weather: 'rain',
mood: 'relaxed'
myAtmosphere: function(weather) {
console.log(this.mood + this.weather)
console.log(this);
};
}
const newWeather = new myTown('sunny');

newWeather.mood();



// Principle 4

// code example for Explicit Binding
const myTown = {
weather: 'rain',
mood: 'relaxed'
myAtmosphere: function(weather) {
console.log(this.mood + this.weather)
console.log(this);
};
}
const newWeather = new myTown('sunny');
const newMood = new myTown('exhausted');

newWeather.myAtmosphere.call();
newMood.myAtmosphere.apply();