# Help making a post/comment

Hi everyone. New here… I’m trying to add a comment to this post and I cannot. Am I missing something? Is the comment section locked? freeCodeCamp Challenge Guide: Find the Longest Word in a String

I want to make a comment that for learners following the JS course, we have not learned the .split method yet so we won’t be able to answer this without looking at the solution.

to contribute to the guide please open a thread in the #contributors subforum, posting your proposed solutions and/or hints, and also if there are already other solutions why you think your solution or explanation should be added.

Please include the link to the challenge and/or the #guide thread, and hide the solution using `[details="Solution"]` on the line above the solution and `[/details]` on the line below the solution

2 Likes

Thanks @ilenia I’ll create a new thread.

This simply did it:

``````function findLongestWordLength(str) {

const word = str.split(' ');

const newArr = word;

newArr.sort();

newArr.sort(function(a, b){

return b.length - a.length;

});

console.log(newArr);

return (word[0]).length;

}

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

Hi @andibraheem!

Welcome to the forum!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thanks a lot. I’m a tech pride trying to get along. I should be better over time. Once again, thanks.

``````function findLongestWordLength(str) {
let strArray = str.split(' ');
let biggestNum = strArray[0];
strArray.forEach(item => {
if(item.length > biggestNum.length){
biggestNum = item
}
});
return biggestNum.length;
}

let biggestStr = findLongestWordLength("The quick brown fox jumped over the lazy dog");
console.log(biggestStr);
``````