Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Return the N-th value of the Fibonacci sequence

function fibonacci(n) {
	// write your solution here
    let fibo = [0, 1]
    for (var i = 2; i <= n; i++) {
        fibo[i] = fibo[i - 1] + fibo[i - 2];
    }
    return fibo[n] 
}

console.log(`fibonacci value at position 5: ${fibonacci(5)}`)
 
PREVIOUS NEXT
Tagged: #Return #Fibonacci #sequence
ADD COMMENT
Topic
Name
9+2 =