Longest word in a String Missing semicolon

In the grand scheme of things yes, I am probably looking at it incorrectly.
Looking at each word in the string, counting how many letters are in each word.
Starting with word one, compare to word two. Whichever is longer, compare that to the next word and so forth until all words have been iterated. Return the remaining word.

Also, thank you for sticking around and helping me. I really appreciate it.

Yeah, you’ve got the right mental flow, so it’s a question of getting that mental flow to match your code.

1 Like

I got the answer, and it was all thanks to you forcing me to rethink my code and where I had gone wrong. I was returning word and not longestWord. This passed the tests!!!
It differs from the solutions that they give, so I am pretty excited about that!

//Looking at each word in the string
//counting how many letters are in each word.
//Starting with word one, compare to word two. 
//Whichever is longer, compare that to the next word and so forth until all words have been iterated. 
//Return the remaining word.

function findLongestWordLength(str) {
let words = str.split(' '); 
let longestWord = words[0]; 
for(let i = 1; i < words.length; i++) { 
    let word = words[i]; 
    if(word.length > longestWord.length){ 
        longestWord = word; 
    }
}
  return longestWord.length; 
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");

1 Like

Nice work!