"Find Longest Words Length in a String" Challenge

I wrote a code which works properly and returns exact result but when I try to submit it FCC does not accept the solution. Later I saw solution from get hint section and passed the challenge from their way of coding.This is my coding.

  function findLongestWordLength(str){
    let arr = str.split(' ');  
    let newArr = [];
    for (let i = 0; i < arr.length ; i++) {
      newArr.push(arr[i].length);
      }
      return console.log( Math.max(...newArr))
    }
    
    findLongestWordLength("A quick brown fox jumped over a lazy dog");

I see here you’re returning a console.log() rather than returning the outcome itself.
try returning the outcome by removing that console.log. and then it should work, if it doesnt then
could you share the freecodecamp solution as well, so as to i can check it thoroughly about the challenge and its required solution

3 Likes

console.log doesn’t return anything: it’s a helper for debugging, all it does is print a value to the console. So with return console.log( you’re just saying “return nothing” (and in JS that will mean you are just returning undefined)

1 Like

can you send link of the challenge?

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string/

Thank you for your reply. It works.