function LongestWord(sen) {
let arr = sen.split(' ');
let longestWord;
for (let i = 0; i < arr.length; i++) {
let counter = 0;
if (arr[i].length > counter) {
counter = arr[i].length;
longestWord = arr[i];
}
}
return longestWord;
};
The objective of the function is to cycle through an array and find the longest word. I've been looking through this and everything seems correct, though, obviously something is wrong but I am not seeing it.
forloop.