# Find the Longest Word in a String.Help

Find the Longest Word in a String.Help
0

#1

Tell us what’s happening:
What is going wrong.Can you help me?

``````
function findLongestWordLength(str) {
var splitString = str.split(" ");
var biggestWord = 0;
for (var i = 0;
i<splitString.length;
i++) { if (biggestWord < splitString[i].length){
biggestWord- splitString[i].length;
}
}
return biggestWord;
}

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

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

#2

I’m looking at this line and I don’t see how this helps you find the longest word.
It looks like you are trying to do a subtraction?

#3

No but I belive that was right in my code.And now what I should do?

#4

I don’t understand why you are doing a subtraction…

#5

I don’t do a subtraction but I belive this is right but you tell that isn’t right.

#6

function findLongestWordLength(str) {
var splitString = str.split(" ");
var biggestWord = 0;
for (var i = 0;
i<splitString.length;
i++) { if (biggestWord < splitString[i].length){
biggestWord= splitString[i].length;
}
}
return biggestWord;
}

findLongestWordLength(“The quick brown fox jumped over the lazy dog”);
I belive this code it’s right.Right

#7

Hi Klaudia

it looks good now. Did you try it?

#8

try this

``````function findLongestWordLength(str) {
var splitString = str.split(" ");
var biggestWord = "";
for(let i = 0; i < splitString.length; i++){
if(biggestWord.length < splitString[i].length){
biggestWord = splitString[i];
}
}
return biggestWord.length;
}

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

#9

This is right Thank oyu for help.

#10

I don’t try it but my new code it is right.But thank you also.