Help on Find the Longest Word in a String algorithm

I thought I solve this algorithm beautifully. lol However, my return statement gives me an error message. See my code and error message below. Can anyone tell me what I’m doing wrong? :slight_smile: Thank you.

“SyntaxError: Illegal return statement”

function findLongestWord(str) {
  var newArray = str.split(' ');
  var i = 0;
  var b = 0;
  
  while( i  <= newArray.length() )
 
      if( newArray[i].length >= b){
          b = newArray[i].length; 
      }
  
      i++;
    }
  
  return b;
}

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

Okay…I got too excited with my code without going over the easy stuff. I believe I corrected all of the major fixes. However, I do have a new error message. Which I guess is a good thing. Error messages does lead to learning something new. LOL

Type error: Cannot read property 'length' of undefined.

function findLongestWord(str) {

var newArray = str.split(’ ');
var i = 0;
var b = 0;

while( i <= newArray.length){

if( newArray[i].length > b){
b = newArray[i].length;
}

i++;
}

return b;
}

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

What does my error message really mean?

I got it. Thank you again.