26. JavaScript Program to find the given number is Palindrome or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Palindrome number or not using JavaScript.
- A palindrome number is a number which means if it remains same even after reversing the digits.
- A number said to be a palindrome if original number is equal to the reverse number other wise it is not a palindrome.
Here is the code
<html>
<head>
<title>JavaScript program to Check a given number is Palindrome or Not</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter a number"> </td>
</tr>
<tr>
<td> <button onclick="palindrome ()" >Submit</button> </td>
</tr>
</table>
<div id="num" ></div>
</body>
<script type="text/javascript">
function palindrome()
{
var a,n,r = 0;
n = parseInt(document.getElementById ("first").value);
n1 = n;
while(n > 0)
{
a = n%10;
n = parseInt(n/10);
r = r*10+a;
}
if(n1 == r)
{
document.getElementById ("num").innerHTML = r+" is a palindrome ";
}
else
{
document.getElementById("num").innerHTML = r+" is not a palindrome";
}
}
</script>
</html>