+ 1
function isPalindrome(number) {
number = number.toString();
var reverse = number.split("").reverse().join("");
return (reverse == number) ? true : false;
}
function doMathStuff(a) {
for(var i = 0; i < 5; i++) {
var b = a.toString().split("").reverse().join("");
var c = a + parseInt(b);
document.write((i + 1) + ': ' + a + ' + ' + b + ' = ' + c + '<br />');
if(isPalindrome(c)) {
document.write('is palindrome');
break;
} else {
document.write('nope<br />');
a = c;
}
document.write('-------------<br />');
}
}
doMathStuff(12545);
// don't need the document.write lines, they just output it nice to view
// OUTPUT
1: 12545 + 54521 = 67066
nope
-------------
2: 67066 + 66076 = 133142
nope
-------------
3: 133142 + 241331 = 374473
is palindrome