I cant pass this test

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function findLongestWordLength(str) {
let words = str.split('');
let maxLength = 0;
for(let i = 0; i < words.length; i++){
  if (words[i].length > maxLength) {
    maxLength = words[i].length
  }
}
return maxLength;
}

  **Your browser information:**

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

Challenge: Find the Longest Word in a String

Link to the challenge:

I suggest you check the values of all your variables with a console.log, so you will find out where it goes wrong

2 Likes
let words = str.split('');

It should be

let words = str.split(' ');

seems like you just had a typo. Its just a minor issue. use console.log() frequently, you can easily find the typo through it.

edit: just noticed the other guy also explained it. :sunny: guess the hot weather is getting to me…

hi there,

  1. although not a requirement for this challenge, you may take an extra mile to identify which substring/s from the original array ‘arr1’ has/have the longest length (and even identify the index/indices of the longest substring/s).

  2. the final result may look like the following example:

arr1: [What,is,the,average,airspeed,velocity,of,an,unladen,swallow]
lengthArray: [4,2,3,7,8,8,2,2,7,7]
longestWordArray: [airspeed,velocity]
longestWordIndexArray: [4,5]
Longest Word Length: 8 characters

Happy coding!

remember that the tests check what is returned from the function, in this case it expect a number, if you try to return all that the tests fail