I was wondering if someone could take a look at the code below and tell my why it won’t pass the tests. I wrote the same code on repl.it and it works just fine, but when on FCC I fail all the test sentences except “May the force be with you”
Your code so far
function findLongestWord(str) {
var array = str.split(" ");
var max = array[0];
for (var i = 0; i < array.length; i++) {
if (max.length < array[i].length) {
max = array[i];
return max.length;
}
}
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7
.
Link to the challenge:
https://www.freecodecamp.org/challenges/find-the-longest-word-in-a-string