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
19 changes: 14 additions & 5 deletions constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@ function Animal(options) {
this.name = options.name;
}

Animal.prototype.grow = function(name){
console.log(`${this.name} grew larger!`);
}
// add 'grow' to Animal's prototype here

// problem #2
// setup Cat to inherit from Animal
// the Animal constructor needs to be invoked with the 'options' argument
// Cat should have its prototype inherit from Animal
// instances of Cat should also have access to the 'grow' method
Cat.prototype = Object.create(Animal.prototype);


function Cat(options) {
Animal.call(this, options);

// invoke Animal here with .call
}



// connect the prototypes here

// if everything is setup properly the code below will print 'Foofie grew larger!'
// uncomment the code below to test your solution

// const foofie = new Cat({
// name: 'foofie',
// });
//
// foofie.grow();
const foofie = new Cat({
name: 'foofie',
});

foofie.grow();

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "help",
"version": "1.0.0",
"description": "* Recursion\r * the `this` keyword\r * constructor functions\r * classes\r ### Instructions\r * This repository is provided as more of a follow along structure.",
"main": "classes.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Siddartha08/JavaScript-II-Mini.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Siddartha08/JavaScript-II-Mini/issues"
},
"homepage": "https://github.com/Siddartha08/JavaScript-II-Mini#readme"
}
21 changes: 18 additions & 3 deletions recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ while (n <= 10) {
}

// write a recursive - function called countToTen that mimics the while loop above.
let num = 1;
const countToTen = (num) => {
if(num > 10) return;
console.log(num);
countToTen(num + 1);

}

// code here

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

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

// write the above functionin a recursive way.
//n * n - 1
const recursiveFactorial = (num) => {
//base case: num === 0 return 1
if (num === 0) return 1;

return num * recursiveFactorial(num - 1);
}



// when you code is ready, un-comment the next line and run the file
// console.log(recursiveFactorial());
console.log(recursiveFactorial(5));
33 changes: 33 additions & 0 deletions this.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,49 @@ console.log('hello world!');

// Principle 1

function whatIsThis(){
consol.log(this);
}
whatIsThis();

// code example for Window Binding

// Principle 2

let newObj = {
name: 'name',
whatIsThis: function(){
console.log(this);
}
};
newObj.whatIsThis();

// code example for Implicit Binding

// Principle 3

function User(name, pass, email){
this.username = name;
this.password = pass;
this.email = email;
this.getsPass = function(){
console.log(`${this.username}, ${this.password}`);
}
}

let jp = new User('jp', '123456', '[email protected]');
let alex = new User('alex', '456123', '[email protected]')
// code example for New Binding

// Principle 4

jp.getsPass.bind(alex);


jp.getsPass.call(alex);

let arr = ['secret', 'anotherSecret']

jp.getsPass.apply(alex, arr);

// code example for Explicit Binding