Created
September 12, 2014 16:17
-
-
Save manderly/41d03642d224abccf90b to your computer and use it in GitHub Desktop.
JavaScript exercise: Find the highest Fibonacci number under 100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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