0

I have code to take the input of a text box and tell the user whether it is a Palindrome or not. What codes do you use to take that word and show the reversed spelling? Here is my current code:

<script type="text/javascript" language="javascript">
function checkPalindrome() 
{
var revStr = "";
var str = document.info.string.value;
var i = str.length;

for(var j=i; j>=0; j--)
    {
        revStr = revStr+str.charAt(j);
    }
    if(str == revStr) 
    {
    window.alert(str+" is Palindrome");
    } 
    else 
    {
    window.alert(str+" is not a Palindrome");
    }
}

</script>
ErikE
  • 48,881
  • 23
  • 151
  • 196
Brian
  • 11
  • 1

1 Answers1

2
str.split('').reverse().join('')
tymeJV
  • 103,943
  • 14
  • 161
  • 157
Bobby
  • 21
  • 1
  • 1
    @tymeJV ... so jealous it stopped me from editing it with the exact same edit seconds before you! :P Bobby this answer is exactly great, but you will want to make sure you set it in code format AND try to explain it for those coming after you. This one is more straight forward, but it is good practice to provide an explanation! – Cayce K May 01 '15 at 19:30