Use JavaScript to recursively calculate the Fibonacci sequence.

Calculating the Fibonacci Sequence Recursively in JavaScript
Recursion—solving a problem by having a function call itself in a loop. The classic example? Calculating the Fibonacci sequence. That’s exactly what this little script does, using recursion to get those numbers that seem to pop up everywhere (rabbits, pine cones, you name it).
You can run this code and pass in a parameter directly. If you don’t, it’ll just politely ask you for a number in the command line and then do its thing.
// JavaScript read/write for the command line
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
// Fibonacci sequence function, using recursion
function fibo(index) {
if (parseInt(index) < 2) {
return 1;
}
return fibo(index - 1) + fibo(index - 2);
}
// If you pass a number in when you run the script, use that
if (process.argv.length > 2) {
let index = parseInt(process.argv[2]); // argv[0] is node.exe, argv[1] is this file's name
console.log(`the fabonacci sequence of ${index} is ${fibo(index)}`);
process.exit(0);
}
// If no number was passed in, ask for one here
console.log("please input an integer to calculate the fabonacci sequence");
rl.on('line', (index) => {
console.log(`the fabonacci sequence of ${index} is ${fibo(index)}`);
rl.close();
})


