Tell us what’s happening:
Been banging my head for an hour now trying to figure out why it’s returning the length of the entire string and not separating the words out into an array. I thought that the split function did that automatically?
A push in the right direction would be most helpful
Your code so far
function findLongestWordLength(str) {
let strSplit = str.split(" ");
let longest = 0;
for(let i = 0; i < str.split.length; i++) {
if(strSplit[i].length > longest) {
longest = strSplit[i].length;
}
}
return str.length;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
console.log(findLongestWordLength("The quick brown fox jumped over the lazy dog"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
Challenge: Basic Algorithm Scripting - Find the Longest Word in a String
Link to the challenge: