Friday, August 18, 2017

Palindrome Using JQuery and JavaScript

In this article I wrote a simple program to check if the given word by the user is a Palindrome or Not a Palindrome. A Palindrome word refers to a word that when we read forward and backwards the spelling is the same and it's sound also. Examples of Palindrome words are below:

  • Anna
  • Civic
  • Kayak
  • Level
  • Madam
  • Mom
  • Noon
  • Racecar
  • Radar
  • Redder
  • Refer
  • Repaper
  • Rotator
  • Rotor
  • Sagas
  • Solos
  • Stats
  • Tenet
  • Wow
I wrote the code using JQuery and JavaScript I hope you will like my work. Thank you very much for visiting my website.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.






Sample Program Output


Program Listing

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Palindrome Using JQuery and JavaScript</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
            var words = $("textarea").val();
var flag = true;
var  str = words.toUpperCase();
         for( var i = 0; i <= words.length-1; i++){
if( words[i] !== words[words.length - i-1]){
flag = false;  
}
}
if(flag == false){
  
output = 'The word ' + str +' is not a Palindrome!';   
}
else {
output = 'The word ' + str + ' is a Palindrome!';
}
document.getElementById("result").innerHTML = output;
        });
    });
</script>
  <style>
   body {
     font-family:arial;
font-weight:bold;
background-color: lightgreen;
size:12px;
   }
  </style>
</head>
<body>
    <br>
<h2>Palindrome Using JQuery and JavaScript</h2>
<br>
    Enter a word 
    <textarea cols="80"></textarea>
    <br><br>
    <button type="button" title="Click here to check if the given work is a Palindrome.">
Ok</button>
<br><br><br>
The result : <span id="result"></span>
</body>
</html>                                



No comments:

Post a Comment