Where did I went wrong?

Tell us what’s happening:

Your code so far


function findLongestWordLength(str) {
str = str.split(" ");
if (str.length == 1) {
return str[0].length;
}

}
if (str[0].length >= str[1].length) {
str.splice(1, 1);
return findLongestWordLength(str.join(" "));
}
if (str[0].length <= str[1].length) {
return findLongestWordLength(str.slice(1, str.length).join(" "));
}

Your browser information:

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

Challenge: Find the Longest Word in a String

Link to the challenge:

So your function should be returning the length of the longest word.

You might try using a for loop.

Let me know if that helps :slight_smile:

You closed the function after the first if statement. Move the closing } to the bottom.

The ultimate goal here is to return the largest string in a sentence. You’re going into the right direction when you think of str.split, but think to yourself: “is that really a string?” Hint: this is where typescript comes in handy. Then you want to find a way to find each length of the number, and find the max.

Another Hint: Math.max() could help you.

The code works just fine, it’s just a malformed function. All they need to do is closed the function correctly.