Palindrome Check in javascript


Write a javascript function to check whether a word or a sentence is palindrome or not irrespective of case and spaces. Name the HTML file as palin.html.

Give appropriate alerts on click of a button name is “palinbtn”. Also provide a text box named “palin” which accepts the word / sentence. The screen should be as shown in the snapshot


  • LiRiL – The entry is a palindrome.
  • Apple – The entry is not a palindrome.
  • Was it a cat I saw – The entry is a palindrome.
Quiz for Exam - Palindrome Check
Quiz for Exam – Palindrome Check

Note : Remove all white spaces from the input given and check for palindrome for the same input ignoring case.



            function palindrome()
                var str=document.getElementById("palin").value;
                var str=str.replace(/\s/g,"").toLowerCase();
                var input=str.split("");
                var output=input.reverse().join("");
                if(str==output) alert("The entry is a palindrome.");
                else alert("The entry is not a palindrome.");
        Enter word/sentence to check for palindrome : <input type="text" name="palin" id="palin"><br>
        <input type="button" name="palinbtn" value="Check Palindrome" onclick="palindrome()">


Leave a Comment

Your email address will not be published. Required fields are marked *