Project euler - don't understand whats wrong with my code

I’m trying to solve project Euler problem 4. I wrote this code and tried to improve it. but I don’t understand what’s wrong with it that it doesn’t give the answer :frowning:

function largestPalindromeProduct(n) {
    var bigNum;
    var base;
    base = Math.pow(10, n);
    bigNum = base-1;
    maxPal(bigNum);
}

largestPalindromeProduct(3);

function maxPal(bigNum) {
    var mayPal;
    mayPal = bigNum * (bigNum - 1) * (bigNum - 2);
    if (isPal(mayPal) == true) {
        return mayPal;
    } else {
        bigNum--;
        maxPal(bigNum);
    }
}

function isPal(number) {
    var rem, temp, final = 0;
    var number;

    temp = number;
    while (number > 0) {
        rem = number % 10;
        number = parseInt(number / 10);
        final = final * 10 + rem;
    }
    if (final == temp) {
        return true;
    } else {
        return false;
    }
}

Take a look at the largestPalindromeProduct function and else case in maxPal function, there’s missing something important in both of these.

1 Like

are you referring to the fact that they dont have “return something” ?

i imagine that was the issue

Look here, maxPal is called, and then? what do you do with the returned value? nothing at all, thats what you do.

1 Like