Skip to content

Commit 3f7aa11

Browse files
committed
completed constructors in JS-II mini, I believe that I did it correctly, however, the test outputs some interesting stuff
1 parent 9984cc2 commit 3f7aa11

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

constructors.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,33 @@ function Animal(options) {
88
this.name = options.name;
99
}
1010

11+
1112
// add 'grow' to Animal's prototype here
1213

14+
Animal.prototype.grow = function () {
15+
console.log `${this.name} grew larger!`
16+
}
17+
1318
// problem #2
1419
// setup Cat to inherit from Animal
1520
// the Animal constructor needs to be invoked with the 'options' argument
1621
// Cat should have its prototype inherit from Animal
1722
// instances of Cat should also have access to the 'grow' method
1823

1924
function Cat(options) {
20-
// invoke Animal here with .call
25+
Animal.call(this, options);
2126
}
2227

2328
// connect the prototypes here
2429

30+
Cat.prototype = Object.create(Animal.prototype);
31+
2532
// if everything is setup properly the code below will print 'Foofie grew larger!'
2633
// uncomment the code below to test your solution
2734

28-
// const foofie = new Cat({
29-
// name: 'foofie',
30-
// });
31-
//
32-
// foofie.grow();
35+
const foofie = new Cat({
36+
name: 'foofie',
37+
});
38+
39+
foofie.grow();
3340

recursion.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ console.log(countToTen(1));
2222

2323
// Problem 2:
2424

25-
//const factorial = n => {
26-
// let result = 1;
27-
// for (let i = 2; i <= n; i++) {
28-
// result *= i;
29-
// }
30-
// return result;
31-
//};
25+
const factorial = n => {
26+
let result = 1;
27+
for (let i = 2; i <= n; i++) {
28+
result *= i;
29+
}
30+
return result;
31+
};
3232

3333
//console.log(factorial(5));
3434

0 commit comments

Comments
 (0)