Public
Edited
Jan 29, 2023
Paused
Insert cell
Insert cell
Insert cell
Insert cell
function iterativeFactorial(n) {
let product = 1;
while (n > 0) {
product *= n;
n--;
}
return product;
}
Insert cell
iterativeFactorial(3) // Try changing the input to test out the function
Insert cell
function recursiveFactorial(n) {
if (n === 0) return 1;
return n * recursiveFactorial(n - 1);
}
Insert cell
recursiveFactorial(3) // Try changing the input to test out the function
Insert cell
Insert cell
function iterativeFibonacci(n) {
let result = 0;
while(n>=0) {
result += n;
n--;
}
return result;
// TODO your code goes here
}
Insert cell
Insert cell
function recursiveFibonacci(n) {
if(n==0) return 0;
if(n==1) return 1;
return recursiveFibonacci(n-1) + recursiveFibonacci(n-2);
// TODO your code goes here
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
iterativeFibonacci(n)
Insert cell
recursiveFibonacci(n)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more