Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fibonacci series is a set of numbers where the next number is the sum of the pre

ID: 3697397 • Letter: F

Question

Fibonacci series is a set of numbers where the next number is the sum of the previous 2.

So if the first number is 0 and second number is 1, the next number number will be 0+1 = 1 and the series will be 0,1,1

The next number will be 1+1 = 2 and the series will be 0,1,1,2 and the next will be 2+1 = 3 making the series 0,1,1,2,3. The next one being 3+2 = 5 then 5+3 = 8 and so forth.

For this assignment write a Fibonacci series for the first 10 numbers using JavaScript. The first two seed numbers will be 0 and 1.

Print the first 13 number of the series

0 1 1 2 3 5 8 13 21 34 55 89 144.

Load the series on body load. This means you will need to have you body tag as <body>

You will need to write your function. Print the first two seed numbers outside your for loop using

document.writeln(number1);

document.writeln(number2);

After this inside your function you will need to create a for loop that will contain the rest of the series.

Explanation / Answer

<html>

<scriptlanguage>="JavaScript"

function yourFunctionName() {

var number1, number2, number3,n;

n=parseInt(prompt("Enter number"));

number1=0;

number2=1;

document.writeln(number1);

document.writeln(number2);

for(var i=3;i<=n;i++) {

number3=(number1+number2);

document.writeln(number3);

number1=number2;

number2=number3;

}

}

</script>

<body>

< a href=""onClick="yourFunctionName()">fibonanci series</a>

</body>

</html>