0

Why does this output 1, even if i set it's "index" value to anything above 1 or 2?

var numberBefore; var numberNow; var index; index = 10; if (index == 0){ document.write("Invalid Number"); }else if((index==1)||(index==2)){ document.write(1); }else{ numberBefore = 1; numberNow = 1; for (var i=0;i<=index;i++){ numberBefore = numberNow; numbernow = numberNow + numberBefore; } document.write(numberNow); }

20th Aug 2019, 7:46 PM
Henry Hefler
Henry Hefler - avatar
2 Answers
0
JavaScript is a case sensitive language. You have to change „numbernow“ to „numberNow“ in the loop.
20th Aug 2019, 7:56 PM
Michael
Michael - avatar
0
i... cant... believe...it was that
20th Aug 2019, 7:58 PM
Henry Hefler
Henry Hefler - avatar