Tell us what’s happening:
Hello campers,
I tried to do this exercise a few times before ending up with this solution, and even though the console returns 5, for the phrase “May the force be with you” (which is correct), it keeps saying that its wrong.
Your code so far
var arraycompare = [];
function findLongestWord(str) {
var array = str.split(" ");
for (var i=0; array.length>i; i++){
arraycompare.push(array[i].length);
}
var sortedarray= arraycompare.sort(function(a, b){
return b-a;
});
var result = sortedarray[0];
return result;
}
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/60.0.3112.101 Safari/537.36
.
Link to the challenge: