Find the Longest Word in a String:basic algorithm

Find the Longest Word in a String:basic algorithm
0.0 0


what is the problem with my function

function findLongestWord(str) {
  var doc=str.split("");
  var lol=doc[0];
  for(var i=0;i < doc.length;i++){
    if(doc[i].length > lol.length){
 return lol.length; 

findLongestWord("the lazy dog");


I would recommend getting handy with the browser console (accessible from your Chrome or Firefox menu, not the in-lesson one) and debugging using console.log(variableName); If you write:
after you declare var doc at the top of your code, you should see why. Also, get friendly with the Mozilla Developer Network javascript reference. they have examples, but if you scroll past that, you get a precise description of the inputs and outputs for functions, for example: str.split();


You could also try Python Tutor.

If you look at the str.split() function (suggested above) you will discover the problem.


Now I got it,the problem is that i forget to write a white space in between the string literal