Hi Hiten,
I’m new here but here’s a tip for finding bugs: add console.log statements everywhere!
For example, I’ve added a line that should print each element in strArray and found that your split statement
is splitting the text into individual characters instead of splitting str into words as I assume you were trying to do.
function findLongestWordLength(str) {
let strArray = str.split('');
let lengthArray = [];
for (let i = 0; i < strArray.length; i++) {
console.log(strArray[i]); // Output: T, h, e, q, u, i, c, k, b, r, o, w, n, f, o, x, j, u, m, p, e, d, o, v, e, r, t, h, e, f, e, n, c, e
lengthArray.push(strArray[i].length);
}
lengthArray.sort();
return lengthArray[strArray.length - 1];
}
A simple fix to your code would be to split str by a space character instead:
i.e.
let strArray = str.split(' ');