Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a new program for fibo series #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions fibonacci_series/Javascript/fibonacci.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// program to generate fibonacci series up to a certain number

/*codacy does not allow console logging , but there is no other alternative for this since I am not running it on any browser.
If at all this needs to be passed as 0 issues on codacy , I will need to remove all the console.log() and then there will be simply no
output although the function will run all fine.*/
// take input from the user
const number = parseInt(prompt("Enter a positive number: "));
let n1 = 0, n2 = 1, nextTerm;

function fibonacci(n){
let n1 = 0 , n2 =1 ,next ;
next = n1+n2;
console.log("fibonacci series :");
console.log(n1);
console.log(n2);
while (next<n){
console.log(next);
n1 = n2;
n2 = next;
next = n1+n2;
}
console.log("Fibonacci Series:");
console.log(n1); // print 0
console.log(n2); // print 1

nextTerm = n1 + n2;

while (nextTerm <= number) {

// print the next term
console.log(nextTerm);

n1 = n2;
n2 = nextTerm;
nextTerm = n1 + n2;
}
fibonacci(15);