JavaScript

JavaScript Function to Checks String is Palindrome or Not?

JavaScript Function to Checks String is Palindrome or Not

Write a JavaScript function, to check string is palindrome or not.

<html>

  <head>

      <title>

          Palindrome

        </title>

      <script type="text/javascript">

      function checkInput(){

          var str = document.form1.palindrome.value;

          palindrome(str);

      }

            function reverse_string(str){

              var  stri = "";

              var  alen = str.length;

              for (var i = alen ; i > 0 ; i--){

                    stri += str.charAt(i-1)

               }

              return stri;

            }

            function palindrome(str){

                    if(str == reverse_string(str))

            alert("palindrome");

          else

            alert("Not Palindrome");

            }

            </script>

    </head>

    <body>

      <form name="form1">

          Text: <input type="text" name="palindrome" />

            <br /><input type="button" value="Check" onclick = "checkInput()" />

        </form>

    </body>

</html>

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

javascript
JavaScript

JavaScript – Introduction, History, and Syntax

  • September 17, 2020
What is “JavaScript”? The first appearance of JavaScript was made in Netscape 2.0 in 1995 with a name Live Script.
javascript
JavaScript

JavaScript – Write Program to Print Hello World!!!

  • September 17, 2020
JavaScript is scripting language which is similar to C. It is syntax and logic are similar to C, C++ and