How do I take two strings and compare them? My last attempt was to put them into arrays but that causes an error. I am stuck.
<script type=”text/javascript”>
/* <![CDATA[
//declare s1 as a variable and prompt user for a word
var s1 = prompt(“enter a word”);
s1 = s1.toUpperCase() // make word upper case
var j;
// reverses the word entered by the user
for (var i = s1.length – 1; i>=0; i–, j++)
{
var s2 = s1; // take word that was reversed and put it in s2
}
// turn them into an array
var arrays = new array();
var array1[] = s1;
var array2[] = s2;
// compare the arrays and display message
for( var j=0;j<array1.length;j++)
{
if(array1[j] == array2[j])
{
alert( s1 + ” is a palindrome”);
else
alert( s1 + ” is not a palindrome”);
}
}
// compare the words and display a message
//if (s1 == s2)
//alert( s1 + ” is a palindrome”);
//else
// alert( s1 + ” is not a palindrome”);
/* ]]>
</script>