File tree Expand file tree Collapse file tree 2 files changed +20
-13
lines changed
Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Original file line number Diff line number Diff 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
1924function 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments