12.
Palindrome using Java Script
String
<html>
<head> <title> JavaScript Palindrome </title>
</head>
<body>
<!-- Use JavaScript programming code to validate the Palindrome numbers or strings. -->
<script>
function validatePalin(str) {
// get the total length of the words
const len = [Link];
// Use for loop to divide the words into 2 half
for (let i = 0; i < len / 2; i++) {
// validate the first and last characters are same
if (string[i] !== string[len - 1 - i]) {
alert( 'It is not a palindrome');
}
}
alert( 'It is a palindrome');
}
// accept the string or number from the prompt
const string = prompt('Enter a string or number: ');
const value = validatePalin(string);
[Link](value);
</script>
</body>
</html>
Number
<!Doctype html>
<html lang = "en">
<head>
<title> Palindrome Program in JavaScript </title>
<style>
h1 {
text-align: center;
padding: 30px;
background-color: skyblue;
color: white;
}
.palindrome {
margin: auto;
width: 40%;
border: 3px solid gray;
border-radius: 5px;
padding: 30px;
}
#palindrome {
width: 100%;
border: 3px solid gray;
border-radius: 5px;
padding: 6px;
}
</style>
</head>
<body>
<h1> Palindrome Program in JavaScript </h1>
<div class="palindrome">
<label> Enter any string or number : </label> <br> <br>
<input id= "palindrome"> <br> <br>
<button type = "button" > Check </button>
</div>
</body>
</html>
<script>
function palindrome() {
var a, b, no, temp = 0;
no = Number([Link] ("palindrome").value);
b = no;
while (no > 0)
{
a = no % 10;
no = parseInt( no / 10);
temp = temp*10 + a;
}
if (temp == b)
{
alert( "It is a Palindrome Number");
}
else
{
alert ("it is not a Palindrome Number");
}
}
</script>