Need some help figuring out where my code is wrong

Hi lads and lassies,

I’m having some issues with the “Find the Longest Word in a String” Challenge.

I wanted to use map to cycle through my first array and output the lengths of each word, then use sort to rearrange them by decreasing order and finally output the first element of the array which should logically be the longest word.

But running this code the console give me the error message: " ReferenceError: lengths is not defined"

And I’m confused since I declared a var named lengths.

function findLongestWord(str) {
  var myArr = str.split(' ');
  var lengths ={
    return word.length;
lenghts.sort(function(a, b) {
  return b - a;
  return lengths[0];

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

What am I missing? Any help is appreciated, thanks a lot.

You have a typo. You spelled lengths as lenghts where you’re about to sort.

1 Like

Oooh man, thanks so much!!

I’ve been stuck on this for hours and I couldn’t see the mistake for the life of me! Thanks you’re a lifesaver!!