function calculate(){

  // This variable is used to keep track of the sum of amicable numbers in the second loop.
  let answer = 0;

  // This loop fill the sum_of_divisors array.
  for(let i = 2; i < value; i++){
    sum_of_divisors[i] = sum_divisors(i);
  }


  // This loops add the amicable numbers to answer
  for(let i = 2; i < value; i++){

    // This is to simplify the checking in the if statement.
    let n = sum_of_divisors[i];

    // You can use this checking 'sum_of_divisors[sum_of_divisors[i]] === i' in the if statement below
    // I added the 'let n' to help simplify the statement.
    if(sum_of_divisors[i] < value && sum_of_divisors[n] === i && sum_of_divisors[i] !== i){  
      answer += i;
    }
  }

  //This is to print the answer on the console.
  console.log(answer);
}
// This function is to calculate the sum of amicable numbers less than 10000.
This function is to calculate the sum of amicable numbers less than 10000.
This function is to calculate the sum of amicable numbers less than 10000 .
function calculate(){
  let answer = 0;
  for(let i = 2; i < value; i++){
    sum_of_divisors[i] = sum_divisors(i);
  }
  for(let i = 2; i < value; i++){
    let n = sum_of_divisors[i];
    if(sum_of_divisors[i] < value && sum_of_divisors[n] === i && sum_of_divisors[i] !== i){  
      answer += i;
    }
  }
  console.log(answer);
}
function calculate ( ) { let answer = 0 ; for ( let i = 2 ; i < value ; i ++ ) { sum_of_divisors [ i ] = sum_divisors ( i ) ; } for ( let i = 2 ; i < value ; i ++ ) { let n = sum_of_divisors [ i ] ; if ( sum_of_divisors [ i ] < value && sum_of_divisors [ n ] === i && sum_of_divisors [ i ] !== i ) { answer += i ; } } console . log ( answer ) ; }
This function is to calculate the sum of amicable numbers less than 10000.
This function is to calculate the sum of amicable numbers less than 10000 .
// This variable is used to keep track of the sum of amicable numbers in the second loop. // This loop fill the sum_of_divisors array. // This loops add the amicable numbers to answer // This is to simplify the checking in the if statement. // You can use this checking 'sum_of_divisors[sum_of_divisors[i]] === i' in the if statement below // I added the 'let n' to help simplify the statement. //This is to print the answer on the console.