Javascript to print Fibonacci series upto 15 Observations

Created at 15-Jan-2021 , By samar

Javascript to print Fibonacci series upto 15 Observations

Through the use of the programming language, we will work together to solve the "Javascript to print Fibonacci series upto 15 Observations" puzzle in this lesson.

  • <script> 
    // take input from the user
    const number = parseInt(prompt('Enter a positive number: '));
    let n1 = 0, n2 = 1, nextTerm;
    
    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;
    } 
    </script>
    
    Code snippets to generate fibonacci series up to a certain number.

Back to code snippet queries related javascript

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.