Std 12th IT Subject - Skill Oriented Practical (Science Stream)
Create event driven JavaScript program for the following.Make use of appropriate variables,JavaScript inbuilt string functions and control structures. To accept string from user and reverse the given string and check whether it is palindrome or not.
<!doctype html>
<html>
<head>
<title>Applicaiton Form</title>
</head>
<script type="text/javascript">
function palindrome() {
var str = f1.t1.value
var len = str.length;
var mid = Math.floor(len / 2);
var check = 0;
for (var i = 0; i < mid; i++) {
if (str[i] !== str[len - 1 - i]) {
check = 1;
}
}
if (check == 0) {
alert("String is a palindrome");
} else {
alert("String is not a palindrome");
}
}
</script>
<body>
<h1>HTML Program to check if the entered string is palindrome or not</h1>
<form name="f1">
Enter String: <input type="text" name="t1">
<input type="button" value="Check" onclick="palindrome()">
</form>
</body>
</html>