Find the longest word works in VS Code but not in FCC

Hi guys,

this code works in VS Code but not in FCC and I don’t get why. :stuck_out_tongue:

function findLongestWordLength(str) {
let words = str.split(" ");
let result = "";
for (word of words) {
  if (word.length > result.length) {
    result = word;
return result.length;

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36.

Challenge: Find the Longest Word in a String

Link to the challenge:

1 Like


When using the for ... of loop you have to declare the variable with let, const or var.

Your word variable is not declared the right way.

More info:

1 Like

Well…that was a really noob mistake! :open_mouth: thanks a lot!

1 Like