Tell us what’s happening:
Describe your issue in detail here.
When I was doing the task of finding the longest word in the string in the JS basic algorithm script and replyto a number, I wrote the code as follows. The Freecodecamp Debug console was not clearly displayed, could you please tell me where I made the mistake? Meanwhile, I have the following doubts: I have practiced HTML+CSS step by step, and now I am practicing JavaScript related content. However, I found that although I have done so much content, I still could not write the required code smoothly. Instead, I needed to retrieve various answers, but it seemed that I did not fully understand them. I will write code as a part of my future life, but I feel low efficiency. Where is my mistake and how can I become an excellent programmer? Please give me your valuable suggestions.
function findLongestWordLength(str) {
let arrary = str.split();
let longestvar = 0 ;
for(let i = 0; i < arrary.length; i++){
if(arrary[i].length > longestvar.length){
longestvar.length = arrary[i].length
}
}
return longestvar.length;
}
console.log(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/90.0.4430.93 Safari/537.36
First I would stop looking up answer and instead ask more questions on the forum when you are stuck. Looking at answers doesn’t help you solve future problems.
I’m taking a look at your code right now and I’ll let you know what I see.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I understand what you mean, numbers have no length, only array and string have length, I modified this line, but my Debug console shows 44, please help me to see what the problem is?