function num(n){ var normal = Math.pow(5, 0.5); if (n<3){ return 1; } return 1/normal * (Math.pow(0.5 * (1 + normal),n) - Math.pow(0.5 * (1-normal),n)); } console.log(num(8));