Find the Longest Word in a String-Code Works-Challenge doesn't accept solution

Find the Longest Word in a String-Code Works-Challenge doesn't accept solution
0

#1

Tell us what’s happening:

Your code so far

var ourArray = [];

function findLongestWord(str) {
  array = str.split(" ");
   for(var i=0; i<array.length; i++) {
ourArray.push(array[i].length); 
   }
  ourArray.sort(function(a,b) {
    return b-a;
  });
  return ourArray[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/60.0.3112.101 Safari/537.36.

Link to the challenge:


#2

Hey
Declare ourArray inside the function.It will work fine.


#3

You are the man!! Thx a lot mate. Cheers.