Home >>Javascript Programs >Check number is palindrome or not in JavaScript

Check number is palindrome or not in JavaScript

Check number is palindrome or not in JavaScript

This tutorial provides how to check a number is a palindrome or not by using JavaScript.

A palindrome number is a number that resembles as same while reading them from backward also are called a palindrome. It is a number that remains the same meaning after rotation from left to right.

For example- 121, 3773, level, etc.

Let's take an example:

<html>
	<head>
		<script>
			function Palnum()
			{
				var rem, temp, final = 0;
				var number = Number(document.getElementById("N").value);

				temp = number;
				while(number>0)
				{
					rem = number%10;
					number = parseInt(number/10);
					final = final*10+rem;
				}
				if(final==temp)
				{
					window.alert("number is Palindrome");
				}
				else
				{
					window.alert("number is not palindrome");
				}
			}
		</script>
	</head>
	<body>
		<br>
		<h1>Check Whether a number is Palindrome or not</h1>
		Enter The Number :<input type="text" name="n" id = "N"/>
   <button onClick="Palnum()">submit</button>
	</body>
</html>
Output:

 

Check Whether a number is Palindrome or not

Enter The Number :


No Sidebar ads