Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fibonacci(n) {
- let firstNum = 0;
- let secondNum = 1;
- if (n > 2) {
- for (let i = 3; i <= n; i++) {
- let currentNum = firstNum + secondNum;
- firstNum = secondNum;
- secondNum = currentNum;
- }
- return secondNum;
- } else if (n === 1) {
- return firstNum;
- } else if (n === 2) {
- return secondNum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement