Javascript to print Fibonacci series upto 15 Observations

Updated 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