This is a general question. I am trying to solve the Fibonacci problem, but it seems that in one of my tries I created an infinite loop and no matter what I do my browser is stack. I can’t delete any of the code from the problem and I can’t stop it. Do you have any idea how I can unstack this so I can solve the problem?
Those kind of problems occur sometimes and I think it’s important to learn how to detect and fix them as fast as possible in order to protect you code. There are problems that can help you do that, such as checkamrx and others. Maintaining your code is important and you should do that.
Good luck with it.
Michael.
I have the same issue however I`m fairly sure that the infinite Loop error is wrong, however the //noprotect still does not help… Can anybody find the error? The code works until num==1000
function fibNum(numToCheck) {
//check if the toAdd number is a fibunacci number
var firstNum = 1;
var secondNum = 1;
var tempNum;
var checkNum = numToCheck;
for(var i=0; i<=numToCheck; i++) {
tempNum = secondNum + firstNum;
firstNum = secondNum;
secondNum = tempNum;
if(numToCheck == tempNum) {
return true;
}
}
}
function isOdd(oddNum) {
//check if the number of the fibunacci row is Odd or not
if(oddNum %2 != 0) {
return true;
}
else return false;
}
function sumFibs(num) {
var sum =0;
for(var i=0; i<=num; i++) {
if(fibNum(i)===true && isOdd(i)===true) {
sum +=i;
}
}
return sum +2;//because they are left out in the first iteration of the fibNum function
}
sumFibs(1000);