Hi all,
today i thought id write a function to see if a string is a palindrome "a word which is spelt the same when read backwards"
and thought id post it on here, to see what other/better ways you guys had of doing it or even though i think my code works, maybe some of you see some bugs i dont know about.
anyways never posted on here before even though i have been registered for a while
<html>
<head>
<script type='text/javascript'>
function handler() {
var string = document.getElementById('string').value;
if (true == isPalindrome(string)) {
alert(string + ": is a palindrome");
} else {
alert(string + ": is not a palindrome");
}
}
function isPalindrome(string) {
if (string.length <= 1) {
return true;
} else if (string.charAt(0) == string.charAt(string.length-1)) {
string = string.substring(1, string.length-1);
return isPalindrome(string);
} else {
return false;
}
}
</script>
</head>
<body>
<button onclick='handler()'>call</button>
<br />
<input type='text' id='string' />
</body>
</html>
anyways all feedback welcome
PS. i got started on this after watching a lecturer do it in python, heres the link
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/lecture-4/
and jump to 42:40 on the time index