Can't find the error :(

Tell us what’s happening:

  **Your code so far**

function findLongestWordLength(str) {
let words = str.split(" ");
let longest = "";

for (let i = 0; i < words.length; i+=1){
  let count = words[i];
  if (count.length > longest.length){
         words = longest; 
  }
}

return longest.length;
}

console.log(findLongestWordLength("The quick brown fox jumped over the lazy dog"));
  **Your browser information:**

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

Challenge: Find the Longest Word in a String

Link to the challenge:

The check for the longest word is correct, but you don’t assign the new longest word to the variable longest, meaning it will always be "". Instead of words = longest you should say longest = count.

PS: “Can’t find the error” isn’t really that great a title. Try to describe your problem. In this case it’s quite easy to find the solution, but in larger problems people won’t be able to help.

1 Like

Thank you very much.
I will be more explicit on the title next time :slight_smile: