I do not understand the reason why this is not working. I am testing until 100 manually and it is operating correctly.
let sumOfProperDivisors = 0;
let number = 0;
let arrayOfAbundantNumbers = [];
let sumOfDeficientNumbers = 0;
let sumOfAbundantNumbers = 0;
let sumOfNumbersWhichCannotBeAdded = 0;
let arrayOfNumbersWhichCannotBeAdded = [];
let limit = 100;
while(number<limit){
for(let i = 1;i<number;i++){
if(number%i==0){
sumOfProperDivisors = sumOfProperDivisors + i;
};
};
if(sumOfProperDivisors>number){
arrayOfAbundantNumbers.push(number);
sumOfAbundantNumbers=sumOfAbundantNumbers + number;
}else{
sumOfDeficientNumbers = sumOfDeficientNumbers + number;
};
for(let i = 0;i<arrayOfAbundantNumbers.length;i++){
for(let j = 0;j<arrayOfAbundantNumbers.length;j++){
if(number==arrayOfAbundantNumbers[i] + arrayOfAbundantNumbers[j]){
arrayOfNumbersWhichCannotBeAdded.push(number);
sumOfNumbersWhichCannotBeAdded = sumOfNumbersWhichCannotBeAdded + number;
//console.log("we cannot add this number to sumOfDeficientNumbers ");
};
break;
};
};
number = number + 1;
sumOfProperDivisors = 0;
};
total = sumOfDeficientNumbers + sumOfAbundantNumbers - sumOfNumbersWhichCannotBeAdded;