I can understand how to get a number but how can I get a different number for different strings?
Your code so far
function findLongestWordLength(str) {
var words = str.split("");
var maxLength = 0;
for (var i = 0; i < words.length; i++) {
if (words[i].length > maxLength) {
maxLength = words[i].length;
}
}
return maxLength;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
I don’t really get what your question is asking, but assuming that you mean every string gives out different numbers meaning the string length. If you do "The quick brown fox jumped over the lazy dog".length; it will return 44, because there is 44 characters inside the string. In your function, you are splitting the sentence into an array and looping through it. So there will be different numbers because each word have different lengths.
It’s literally what you’re doing though, I don’t understand what you’re asking: in your code you are splitting the string then counting the letters in each word in turn