Exp-10 Create event driven JavaScript program for the following. Make use of appropriate variables, JavaScript inbuilt string functions and control structures.

write this on the writing side

To accept string from user and reverse the given string and check whether it is palindrome or not.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form name="f1">
Enter the string to check it is palindrome or not!
<br>
<input type="text" name="t1">
<br>
<br>
<input type="button" name="check_palin" value="Check
String" onclick="chk_palindrome()">
</form>
<script type="text/javascript">
function chk_palindrome()
{
var str,str_case,i,len;
str=f1.t1.value;
str_case=str.toLowerCase();
len=str_case.length;
var p=1;
for(i=0;i<len/2;i++)
{

if(str_case.charAt(i)!=str_case.charAt(len-1-i))

{
p=0;
break;

}
}
if(p==1)
{
alert("Entered string is Palindrome");
}
else
{
alert("Entered string is Not a Palindrome")
}
}
</script>
</body>
</html>

stick this output on the blank side

Leave a Comment

Scroll to Top