JavaScript Program to Create a Functin that Checks Whether String is Palindrome or Not

Write a JavaScript program to create a functin that checks whether string is palindrome or not.

Write a JavaScript function that checks whether a passed string is palindrome or not.



Source Code
<html>
<head>
    <title>String Palindrome or not</title>
<script>
    function checkPalindrome(str)
    {
        var s = 0;
        var e = str.length-1;

        while(s <= e)
        {
            if(str[s] != str[e])
            {
                return str + ' -> is not Palindrome.'
            }
            else
            {
                s++;
                e--;
            }
        }
        return str + ' -> is Palindrome.'				
    }
    document.write(checkPalindrome('madam'));
    document.write("<br>");
    document.write(checkPalindrome('javascript'));
    document.write("<br>");
    document.write(checkPalindrome('nitin'));
</script>
</head>
<body>
</body>
</html>
Output