Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## recursive fibanici

<title>a</title>
<script text="javascript/text">
document.write("the fibanic series is as follows" )
var i;
for (i=0; i<6; i++){ document.write(i);
value=i;
a(value);
}
function a(value){if(value===0){
document.write("1");}
if(value===1){
docuument.write("1");}
else
document.write(a(value-1)+a(value-2));}

</script>
<body></body>
</html>
i used the below written code but the the result that is coming is :
the fibanic series is as follows00

• HINT: There is a HUGE difference between RETURNING a value from a function and doing document.write() of the value inside the function.

• And it’s called Fibonacci, not fibanici.

• docuument

• <script text="javascript/text">

Code:
```<script type = "text/javascript">

var r = [1], n = 1, a = 0, b = 1, next;
function nextFibonacci() {
next = a + b;
return b = (a = b, next);
}
while (n++ < 12) {
r.push(nextFibonacci());
}

alert (r); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
document.write(r);

</script>```
Or simpler:-

Code:
```<script type = "text/javascript">

var fib = [];
fib[0]=1;
fib[1]=1;
var numFib = 12;  // calculate first numFib numbers
for (var c=2; c<=numFib; c++) {
fib[c] = fib[c-1] + fib[c-2];
}
alert ("First " + numFib + " Fibonnacci numbers:- " + fib);
document.write("First " + numFib + " Fibonnacci numbers:- " + fib);

</script>```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•