Longest word in a sentence

Anyone here can help me regarding my code and tell me what is wrong in this code ??
*
*

function findLongestWord(str) {
  string = "";
  s = "";
  a = 0;
  for(var i = 0; i < str.length; i++){
    string = string + str.charAt(i);
    if(str.charAt(i) == " "){
      s = string.length;
      if(s>a){
        a = s;
      }
      
    }
  }
  
  
  return a;
}

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

So, after if statements i should add, string = “” , then will it work??
btw thaks for the answer//
or what should it edit??

Thank you so much…yeah really amazing people here!
But its still not working, i have set string = “” after a = s;
why?
it is returning 12 instead of 6

function findLongestWord(str) {
string = “”;
s = “”;
a = 0;
for(var i = 0; i < str.length; i++){
string = string + str.charAt(i);
if(str.charAt(i) == " "){
s = string.length;
if(s>a){
a = s;
string = “”;
}

}

}

return a;
}

findLongestWord(“May the force be with you”);

its just that every time we find space, we store the length of string before space.And then empty the string and assign it upto the next space we get , then compare its length to the previous string’s length…
Btw now it will work??
And also we resret string after every space…

Thank you so much …
Btw sir what is your job:?
Beside helping students like me…lol

Thats great sir… Any advice for me to get a dev. job faster?
In which topics i should practice most?