Challenge 4
Palindrome numbers read the same forwards and backwards. The largest palindrome that can be formed by multiplying two 3-digit numbers is 9009 = 91 × 99. Your task is to find the largest palindrome made from the product of two 3-digit numbers.
I'm sharing my code below. It successfully finds the largest palindrome for 2-digit numbers, which is 9009. However, when I run the code for 3-digit numbers, the correct answer is 906609 while I'm getting 956459. I can't figure out what's wrong with my code, can someone please help me? Thanks.
let result;//product of two numbers
let palindromes=[];//array for palindrome numbers
for(i=100;i<1000;i++)
{
for (j=100;j<1000;j++)
{
result = i*j;
str= result.toString();//change the number to a string
if (str.substr(0,1) == str.substr(-1,1) && str.substr(1,1) == str.substr(-2,1))
{
palindromes.push(result);
}
else{};
};
};
console.log(palindromes);
console.log(Math.max(...palindromes));