Hello fellow Campers!
I’m having a bit of a problem with the “Find the Longest Word in a String” challenge. The code below works as far as I can tell. I get a check mark for every criterion with the exception of “findLongestWord(“May the force be with you”) should return 5.” The problem is, when I pass that string in the console it does return 5. Is my code incorrect, or is this an error on the site itself? I’ve checked for typos, syntax errors, etc. and can’t find anything wrong. Does anyone else see where I’m messing up?
Thanks so much!
-Spencer
Your code so far
function findLongestWord(str) {
var sentenceArr = str.split(" ");
for (var i = 0; i < sentenceArr.length; i++) {
wordLengths.push(sentenceArr[i].length);
}
wordLengths.sort(function(a,b) {
return b - a;
});
return wordLengths[0];
}
findLongestWord("May the force be with you");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: