Create a javascript program to perform a palindrome test. Before understanding the logic of palindrome in javascript we need to understand what is a palindrome. Below is the definition of palindrome with examples. JavaScript Program to find Palindrome pwb, palindrome javascript by programmingwithbasics, Javascript Palindrome Check.
What is palindrome
A palindrome is a word, phrase, number, or another sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Examples in English include "a man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "was it a car or a cat i saw?" and "no 'x' in Nixon".
Create A HTML WebPage Using JAVASCRIPT For Check Given String In Palindrome Or Not
In Hindi:- "उल्टा सीधा एक समान" or "Ulta Seedha Ek Samaan"
<html>
<head>
<meta charset = "UTF-8">
<title>Palindrome</title>
<style type="text/css">
body
{
font:10px sans-serif;
}
</style>
<script type="text/javascript">
function palindrome()
{
var initial = prompt("Please enter a 5 digit string to check whether it is a palindrome:", "");
var palin = new Array();
while (initial.length != 5)
{
alert("You did not enter a 5 character digit! All palindromes that this calculator can solve are 5 digits!")
initial = prompt("Please enter a 5 digit string to check whether it is a palindrome:", "");
}
for (var i = 0; i <= initial.length -1; i++) {
palin[i] = initial.charAt(i);
};
if (palin[0] == palin[4])
{
if (palin[1] == palin[3])
{
document.write("The number that you entered was " + initial + ".");
document.write("<br>This number is a palindrome!")
}
}
else
{
document.write("The number that you entered was " + initial + ".");
document.write("<br>This number is NOT a palindrome!")
};
};
</script>
</head>
<body align="center" bgcolor="aqua">
<p><h2> Enter a 5 digit string to check whether an the string is a palindrome.</p></h2><br>
<p><h2> A palindrome is a number that reads the same backwards and forwards. </h2></p1>
<hr>
<input type = "button" id = "palindrome" value = "Click to start the program" onclick = "palindrome();" />
</body>
</html>
Output:-
What is palindrome
A palindrome is a word, phrase, number, or another sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Examples in English include "a man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "was it a car or a cat i saw?" and "no 'x' in Nixon".
Create A HTML WebPage Using JAVASCRIPT For Check Given String In Palindrome Or Not
In Hindi:- "उल्टा सीधा एक समान" or "Ulta Seedha Ek Samaan"
Javascript Palindrome Code start from here
<html>
<head>
<meta charset = "UTF-8">
<title>Palindrome</title>
<style type="text/css">
body
{
font:10px sans-serif;
}
</style>
<script type="text/javascript">
function palindrome()
{
var initial = prompt("Please enter a 5 digit string to check whether it is a palindrome:", "");
var palin = new Array();
while (initial.length != 5)
{
alert("You did not enter a 5 character digit! All palindromes that this calculator can solve are 5 digits!")
initial = prompt("Please enter a 5 digit string to check whether it is a palindrome:", "");
}
for (var i = 0; i <= initial.length -1; i++) {
palin[i] = initial.charAt(i);
};
if (palin[0] == palin[4])
{
if (palin[1] == palin[3])
{
document.write("The number that you entered was " + initial + ".");
document.write("<br>This number is a palindrome!")
}
}
else
{
document.write("The number that you entered was " + initial + ".");
document.write("<br>This number is NOT a palindrome!")
};
};
</script>
</head>
<body align="center" bgcolor="aqua">
<p><h2> Enter a 5 digit string to check whether an the string is a palindrome.</p></h2><br>
<p><h2> A palindrome is a number that reads the same backwards and forwards. </h2></p1>
<hr>
<input type = "button" id = "palindrome" value = "Click to start the program" onclick = "palindrome();" />
</body>
</html>
Output:-
Number Is Not Palindrome Example
0 Comments: