Tell us what’s happening:
what is wrong with this code? please help me find a bug.
The code works properly for some sentences except this one.
Your code so far
function findLongestWord(str) {
var a=str.split(' ');
var b=a.map(function(str1){return str1.length;});
var largest=0;
for(var i=0;i<b.length-1;i++)
{
if(b[i]>largest)
largest=b[i];
}
return largest;
}
findLongestWord("What if we try a super-long word such as otorhinolaryngology");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/find-the-longest-word-in-a-string