0% found this document useful (0 votes)
13 views3 pages

JavaLab III

The document provides a JavaScript program for validating palindromes, both for strings and numbers. It includes HTML structure for user input and styles for presentation. The script checks if the entered value is a palindrome and alerts the user accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

JavaLab III

The document provides a JavaScript program for validating palindromes, both for strings and numbers. It includes HTML structure for user input and styles for presentation. The script checks if the entered value is a palindrome and alerts the user accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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" onclick = "palindrome()" > 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>

You might also like