Tell us what’s happening:
I believe my solution for this lab is correct (albeit very long and ugly lol) but I am not sure what the problem is. The tests are saying that im failing here
- findLongestWordLength(“The quick brown fox jumped over the lazy dog”) should return a number.
but I checked with both typeOf() and isNan() for good measure, but both are saying that it is returning a number so I don’t know where I am going wrong. I would appreciate any advice
Your code so far
const findLongestWordLength = (sentence) => {
let end = 0;
let count = 0;
let longest = 0;
for (char of sentence) {
end++;
if (char === " ") {
if (count > longest) {
longest = count;
count = 0;
} else {
count = 0;
}
} else if (end === sentence.length) {
count++;
if (count > longest) {
longest = count;
}
} else {
count++;
}
}
return longest;
};
const test = findLongestWordLength(
"What if we try a super-long word such as otorhinolaryngology"
);
console.log(
test, // 19
typeof test, // number
isNaN(test) // false
);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0
Challenge Information:
Build a Longest Word Finder App - Build a Longest Word Finder App
https://www.freecodecamp.org/learn/full-stack-developer/lab-longest-word-in-a-string/build-a-longest-word-finder-app