Dear team,
pls i am having issues with challenge: Basic Algorithm Scripting: Find the Longest Word in a String
findLongestWordLength(“The quick brown fox jumped over the lazy dog”) should return a number.
findLongestWordLength(“The quick brown fox jumped over the lazy dog”) should return 6.
findLongestWordLength(“May the force be with you”) should return 5.
findLongestWordLength(“Google do a barrel roll”) should return 6.
findLongestWordLength(“What is the average airspeed velocity of an unladen swallow”) should return 8.
findLongestWordLength(“What if we try a super-long word such as otorhinolaryngology”) should return 19.
i used the code below and it didnt work but when i tried it on the console of my browser it worked perfectly…pls what do i do
function findLongestWord(str) {
var strSplit = str.split(" ");
var longestWord = 0;
for(var i = 0; i < strSplit.length; i++){
if(strSplit[i].length > longestWord){
longestWord = strSplit[i].length;
}
}
return longestWord;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
6// this was the returned answer