Hello everyone. This code finds the longest word in a string and returns it as a number (or at least it supposed to). I can get it to pass all the test except when you pass in “May the force be with you”. var longest should return 5 and when I console.log longest, it shows 5. For some reason though I can’t get the code to pass the challenge, any idea what I did wrong?
var longest = 0;
function findLongestWordLength(str) {
let array = str.split(' ');
for (let i = 0; i < array.length; i++) {
if (array[i].length > longest) {
longest = array[i].length;
}
}
return longest;
}
findLongestWordLength("May the force be with you");