I writing a method to find the longest palindrome in a sentence of words. So far I have used the for loop to do this but its not returning the correct word.
function findLongestPalindrome(sentence) {
  let wordArray = sentence.split(" ");
  let longestWord = 0;
  let word = " ";
  
  for(let i = 0; i < wordArray.length; i++) {
    if(longestWord < wordArray[i].length) {
      longestWord = wordArray[i].length;
      word = wordArray[i]
    }
  }
  return word;
}
Can anyone give me a tip on where I am going wrong?
 
     
    