Last active
August 29, 2015 13:56
-
-
Save Morgantheplant/9204522 to your computer and use it in GitHub Desktop.
Prompts user for a price and then returns the next highest palindrome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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