I'm brand new to coding, have only been doing it for about two weeks. I'm doing freecodecamp and i'm having trouble understanding why my code isn't working. The goal is to make a function that receives a string and then finds the longest word and gives you the amount of characters in the word. I would appreciate any advice.
function findLongestWordLength(str) {
let string = /\w+/g;
let arrayString = str.match(string);
let wordCount = arrayString[0].length;
for (let n= 1; n > arrayString.lentgh; n++){
if (wordCount < arrayString[n].length){
return wordCount = arrayString[n].length;
}
}
return wordCount;
}
console.log(findLongestWordLength("Thep quick brown fox jumped over the lazy dog"));