A palindrome is used to verify a sequence of numbers, strings, or letters that are read left to right and right to left to match the same characters or return the same sequence of characters. In simple terms, when the numbers, strings, or characters are reversed that return the same result as the original numbers or characters, it is called a Palindrome. For example, NITIN, 123454321, madam, etc. Suppose we have a word, madam. When we read the word madam from the forward and the backward end, it returns the same string. Therefore, we can refer to the string or number as the Palindrome.
Check Palindrome number and string by accepting the number through prompt box.
string.htmlTest it Now
When the above code is executed, it shows the below image:
Now we enter the number or string on the prompt alert box and then click the OK button to validate the given string is Palindrome or not.
After that, it shows the below Output.
If the given string is not a Palindrome, it shows the string is not a Palindrome. Similarly, we can enter the number and validate whether the given number is Palindrome.
Check Palindrome string using built-in Functions
Program2.htmlTest it Now
When we execute the above code, it shows the below image:
In the above images, we entered a string MADAM and then click the OK button to check the given string is a Palindrome or not.
After that, it shows the below image:
Str.htmlTest it Now
When the above programming code is executed, it returns the below images:
We enter the numbers and click on the Check button to validate the given number is Palindrome, as shown below.
In the above image, it shows that "It is a Palindrome Number." And if the reversed number is not the same as the original number, it shows that the entered number is not a Palindrome.
Str2.htmlTest it Now
When the above programming code is executed, it returns the below image:
We entered the string "MADAM" and then click on the Submit button in the above output. It displays the below result, as shown:
Explanation of the code: When we entered the "MADAM" String in the textbox and then click on the Submit button. After that, the original string "MADAM" is reversed and compares each string's character with the original one. If both strings are equal, it shows that "It is a Palindrome String".
In the above output, when we entered the string JOHN, it displays the string is not a Palindrome string as it does not match the reversed characters of the string with the original.