Skip to content

Instantly share code, notes, and snippets.

@Morgantheplant
Last active August 29, 2015 13:56
Show Gist options
  • Save Morgantheplant/9204522 to your computer and use it in GitHub Desktop.
Save Morgantheplant/9204522 to your computer and use it in GitHub Desktop.
Prompts user for a price and then returns the next highest palindrome.
var ask = prompt("Enter a price to find the next palindromic number!");
var removeDec = function (j) {
return parseInt(j * 100);
}
var c = removeDec(ask);
var reverseIt = function (x) {
var a = ""
x = x.toString();
for (var inn = (x.length - 1); inn >= 0; inn--) {
a = (a + String(x.substr(inn, 1)));
}
return Number(a);
};
var b = reverseIt(c);
var e = Math.pow(10,(String(c).length-1));
if (c == b) {
document.write("$"+(c/100)+"... This price is already palindrome!")
} else {
for (c; c !== b; c++){
b = reverseIt(c);
if ((c+1) == (b + e)) {
document.write("The next palindromic price is $" + ((c+1)/100));
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment