I am trying to solve a very easy challenge about finding the longest word in a string.
This is the code:
function find(par) {
let arrayWord = par.split( );
let longestWord = ;
for (let i = 0; i <= arrayWord.length; i++) {
if (longestWord.length < arrayWord[i].length) {
longestWord = arrayWord[i]
}
}
return longestWord;
}
find(Find the longest word);
I would need help understanding why I am getting this error:
Uncaught TypeError: Cannot read property 'length' of undefined
at find (:5:47)
at :11:1 find @ VM959:5 (anonymous) @ VM959:11
thank you.