Find the Longest Word in a String--Right but doesn't pass...why?

Find the Longest Word in a String--Right but doesn't pass...why?
0

I don’t understand why this isn’t right.
Can someone explain this?
Thanks

function findLongestWordLength(str) {

   let arr = [];
  arr = str.split(' ').map(w => w.length);
  str = Math.max(...arr);
  console.log(str);
    

  return str.length;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string

Think what value you are actually assigning to str here and then fix your return statement.

1 Like

Look at what you have logged to the console.

1 Like

So, str is a number because arr is an array of numbers. You then return str.length, which doesn’t exist because a number doesn’t have a length property

I highly suggest you work in making the variables having meaningful names.
Like don’t use str for a number…