Here's the function I have written right now. The web console isn't doing much for me. Every time a word is entered in the text box, even if it is a palindrome, it just returns "undefinedThis is not a palindrome!"
.
Not sure what's wrong here. Perhaps something to do with the if
statement? How can I make it so that the function ignores capitalized letters? I want it to consider both "bob"
and "Bob"
a palindrome.
function test() {
// Assumes: a string is entered into the "palin" text box
// Results: tests if the string is a palindrome and
// returns the conclusion to outputDiv
var word, copy, i;
word = document.getElementById("palin").value;
copy = " ";
i = 0;
while (i < word.length) {
copy = word.charAt(i) + copy;
i=i+1;
}
if (word === copy) {
document.getElementById("outputDiv").innerHTML =
document.getElementById("outputDiv").value +
"This is a palindrome!";
} else {
document.getElementById('outputDiv').innerHTML =
document.getElementById('outputDiv').value +
"This is not a palindrome!";
}
}