Skip to content

Instantly share code, notes, and snippets.

@manderly
Created September 12, 2014 16:17
Show Gist options
  • Save manderly/41d03642d224abccf90b to your computer and use it in GitHub Desktop.
Save manderly/41d03642d224abccf90b to your computer and use it in GitHub Desktop.
JavaScript exercise: Find the highest Fibonacci number under 100
//Return to me the highest Fibonacci number between 0 and 100
//1,2,3,5,8,13,21,34,55,89
var sum = 0;
var arr = [];
var fibo = function(num1, num2) {
sum = num1 + num2;
console.log('num1: ' + num1 + ' + num2: ' + num2 + ' = sum: ' + sum);
if (sum < 100) {
arr.push(sum);
num1 = num2;
num2 = sum;
fibo(num1,num2);
}
};
fibo(0,1);
console.log("Highest Fibonacci number under 100: " + arr.pop());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment