check string palindrome in JavaScript - Javascript String Operation

Javascript examples for String Operation:String Algorithm

Description

check string palindrome in JavaScript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w  ww  .j ava 2 s. c o m*/
function palindrome(word)
{
    for(var i=0;i<word.length/2;i++)
        if(word.charAt(i)!=word.charAt(word.length-(i+1)))
            return word+" is Not a Palindrome";
    return word+" is Palindrome";
}
console.log(palindrome("madam"));
console.log(palindrome("madan"));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials