Hi! I was trying to complete the " Basic Algorithm Scripting: Find the Longest Word in a String". This is my code:
function findLongestWordLength(str) {
let words = str.split(' ');
let max = 0;
//console.log(word);
words.forEach(function(word, index) {
if (word[index].length > max) {
max = word[index].length;
}
}
)
//console.log(max);
return max;
}
console.log(findLongestWordLength("Google do a barrel roll"));
It returns Cannot read property 'length' of undefined
.
Can anyone help me to figure out what’s wrong? Thanks in advance