Longest word javascript

Tell us what’s happening:
Why last case is failing?

Your code so far


function findLongestWordLength(str) {
  var st = " ";
  var count = 0;
  var arr = []; 
  var j = 0;
  for(var i = 0; i < str.length; i++)
  {
     count++;
    if(st == str.charAt(i))
    {
      arr[j] = count - 1;
      j++;
      count = 0;
    }
   
  }
  return Math.max(...arr);
  //return Math.max(arr);
  //return str.length;
}

findLongestWordLength("The quick brown fox jumped over the lazy dog");

Your browser information:

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

Link to the challenge:

your code is only counting letters before the space, so it never pushes the last count to the array this is why the last test fails, because the longest word is the last word in the string.
hope this makes sense and help you fix the code :slightly_smiling_face: