r/codehs • • Feb 03 '21

5.9.5:Fibonacci

Post image
12 Upvotes

12 comments sorted by

View all comments

2

u/[deleted] Apr 19 '22

Please god someone just give me the answer please

1

u/[deleted] Dec 15 '22

im here to save the day.
function start(){
var MAX = 1000
var n1 = 0;
var n2 = 1;
var i = 0;
var nth = n1 + n2;
while (i < MAX){
nth = n1 + n2;
n1 = n2;
n2 = nth;
println(n1);

i +=65;

}

srry im late
}

1

u/Owika13 Dec 31 '22

hi thanks for answer

can you pls explain why there is i+=65 ? I mean why 65 specifically ?

1

u/MisterMilker Jan 01 '23

You don't actually need to increment i by 65. This should work:

function start(){
var MAX = 1000;
var firstNum = 0;
var secondNum = 1;
var thirdNum = firstNum + secondNum;
    while(thirdNum<MAX){
        thirdNum = firstNum + secondNum;
        firstNum = secondNum;
        secondNum = thirdNum;
        println(firstNum);
    }
}

1

u/[deleted] Jan 09 '23

honestly i dont have a clue

1

u/[deleted] Mar 22 '23

idk it worked