forked from swaaz/basicprograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram-4.html
More file actions
55 lines (47 loc) · 1.32 KB
/
Copy pathprogram-4.html
File metadata and controls
55 lines (47 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Check Palindrome with JavaScript Program</title>
<style>
input{
padding: 10px;
}
</style>
<script>
function myFunction()
{
//get the value from textbox
var str = document.getElementById('txtbox').value;
//call checkPalindrome() and pass str
var result = checkPalindrome(str);
alert('The Entered String "'+str +'" is "'+result+'"');
}
function checkPalindrome(str)
{
var orignalStr;
//lowercase the string
str = str.toLowerCase();
//store the str in orignalStr for future use
orignalStr = str;
//reverse the entered string
str = str.split(''); //split the entered string
str = str.reverse(); //reverse the order
str = str.join(''); //then join the reverse order array values
var reverseStr = str;
//finally check both the Original string stored in orignalStr
//and reversed to find the palindrom
if(orignalStr == reverseStr){
return 'Palindrome'; // return "Palindrome" if true
}else{
return 'Not Palindrome';
}
}
</script>
</head>
<body>
<form>
<input type="text" id="txtbox" placeholder="Enter String" />
<input type="button" onclick="myFunction()" value="Check Palindrome" />
</form>
</body>
</html>