Longest word test

Tell us what’s happening:
Describe your issue in detail here.
Hello. Could someone tell me what’s wrong with my code. The test is not passing and the console keeps printing 1.

  **Your code so far**

function findLongestWordLength(str) {let words = str.split(""); 
let maxLength = 0;
for (let i = 0; i < words.length; i++){if (words[i].length > maxLength){maxLength = words[i].length;}}
return maxLength;

console.log(findLongestWordLength("The quick brown fox jumped over the lazy dog"));
  **Your browser information:**

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1

Challenge: Find the Longest Word in a String

Link to the challenge:

First of all, please format your code. Just get in the habit of doing it while you code. It will save you soooooooooooooo much hassle.

Secondly, you need to think about this line:

let words = str.split("");

This is where your issue issue, here. When I fix that, your code passes for me.

I would recommend using a console.log statement. By this point, that should be your first thought when encountering a problem, learning how to debug your own code.


I fixed the line and the code passed. Thank youu very much. I’ll work on formatting my code.

1 Like