function findLongestWordLength(str){
let newArray = str.split(" ");
let maxLength = 0;
for (let i=0 ; i<newArray; i++){
if (newArray[i] > maxLength)
{
maxLength = newArray[i].length;
}
}
return maxLength;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Calm down and check two below lines one more time, you will know the reason. In my opinion, the best way to debug code is console.log everywhere I am confused.
for (let i=0 ; i<newArray; i++) {
if (newArray[i] > maxLength)
Spending that much time on a problem is normal. When I first started tackling JavaScript algorithms, it sometimes took days to figure something out, it’s all part of the learning experience.
Meow, sure, it’s not ok but very ok because I can say that from now you will always remember about length of array and string, mistakes make you stronger.