function fibonacci(n) {
    if (n <= 2) {
        return 1;
    } else {
        return fibonacci(n - 1) + fibonacci(n - 2);
    }
}

This implementation of the Fibonacci algorithm uses a recursive approach. It checks whether the input number is less than or equal to 2, and if so, it returns 1. If the input number is greater than 2, the function calls itself with the input number decremented by 1 and decremented by 2 and adds both results together. This process continues until the input number is less than 2, at which point the function returns 1 and the previous function calls return their results.

Here's an example of how the function can be used:


console.log(fibonacci(6));  // 8
console.log(fibonacci(10));  // 55