This forum is now read-only. Please use our new forums at discuss.codecademy.com.

## Big O Forum

# Big O 2.5 I am totally lost to what to do here

I am totally lost to what to do here

```
var count = 0;
// Recursively find Xth Fibonacci number
var fib = function(x){
// Keeps track of the amount of work done computing a Fibonacci
count++;
// Base Case
if(x < 10 ) { }
// Recursive calls
return fib( x ) fib( );
}
var f = fib(10);
console.log("It took "+count+" calculations to find that the 10th fibonacci number is "+f+".");
```

**I found your problem! All you have to do is take away the fib(count); from after the return function!**

```
// here is the finished code
var count = 0;
// Recursively find Xth Fibonacci number
var fib = function(x){
// Keeps track of the amount of work done computing a Fibonacci
count++;
// Base Case
if(x < 2 ) { return 1; }
// Recursive calls
return fib( count );
};
var f = fib(10);
console.log("It took "+count+" calculations to find that the 10th fibonacci number is "+f+".");
```

**Hope this helped!**

I'll start you off by giving the base case. If you know the first few values of a Fibonacci series (1, 1, 2), you notice that there's a single point where you can stop asking for the preceding numbers. Since the first two are always 1, when fib(2) is called, it should return 1 without having to look further back (the same goes for fib(1)). So your base case should look something like this:

`if (x <= 2) { return 1; }`

This isn't required by the problem, but as an extra measure, I would also add a clause for values of n <= 0, just so that the 0th term of the fibonacci sequence isn't returned as being 1! So mine looks like this:

`if (x <= 0) { return 0; }`

`else if (x <= 2) { return 1; }`

Like I mentioned, this second part isn't required by the assignment, but it's just something to consider.

Now I'm going to let you figure the part about the recursive calls. Just remember that each time you want to know the nth Fibonacci term, you need to know the preceding two.

Here's the correct answer from start to finish. If you want to figure out the problem yourself this will spoil it!!

```
var count = 0;
// Recursively find Xth Fibonacci number
var fib = function(x){
// Keeps track of the amount of work done computing a Fibonacci
count++;
// Base Case
if (x<=0) {return 0;}//**Optional** Thanks, TenebrousNight :D
if(x<=2){return 1;}
// Recursive calls
return fib(x - 1) + fib(x - 2);
};
var f = fib(10);
console.log("It took "+count+" calculations to find that the 10th fibonacci number is "+f+".");
```

Problem is you can pass this without the right answer. But what I don't understand is why you guy just didn't have:

```
return fib(x-1) + fib(x-2);
```

## 3 Comments

Franzi Vegas over 5 years ago

Thank you, it really helped me.

Tatjana Seketa over 5 years ago

Your welcome.

Sofia Perwallius about 4 years ago

Thank you a lot