Build a Longest Word Finder App (Comparing Lengths) Question

Tell us what’s happening:

I think I understand the basic structure of this project, but somehow, test cases 4, 8, and 9 do not resolve. They seem only to hit the first word that is longer before the longest word in the sentence. I can output each array[i].length in another array, but I do not understand what JavaScript methods to use to compare each of the word’s lengths in that array. I would appreciate a little guidance here.
Thanks!

Your code so far

function findLongestWordLength(string){
  const array = string.split(" ")
  console.log(array)
  let wordLength = []
  for(let i = 0; i < array.length; i++) {
    if(array[i].length > array.length - array[i].length) {
      return array[i].length
    }
  }
  
}
console.log(findLongestWordLength("What if we try a super-long word such as otorhinolaryngology"))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Challenge Information:

Build a Longest Word Finder App - Build a Longest Word Finder App

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-longest-word-in-a-string/a26cbbe9ad8655a977e1ceb5.md at main · freeCodeCamp/freeCodeCamp · GitHub

I think you misunderstood the problem. You need to find the maximum length of all words, so you can create a maxLength variable and compare it with the length of each word to find the maximum. But you are comparing the total word count with each word’s length, which is wrong.

Thank you for your help! I found out that I had to use a Math method on an array of wordLengths to find the maxLength.