im doing the exercise for js but in this case my code is working on my computer not in the page :S
function findLongestWordLength(str) {
let i = [...str];
let contador = 0;
let contadorBase = 0;
i.forEach((celda,index) => {
if(celda === " " || index+1 === i.length){
if(contador >= contadorBase){
contadorBase = contador;
contador = 0;
}else{
contador = 0;
}
}else{
contador++;
}
})
return contadorBase;
}
console.log(findLongestWordLength("What if we try a super-long word such as otorhinolaryngology "));
this returned 19 but the freecodecamp’s test fail… i try not to see the “solutions” unless i really don’t know what to do… any idea why this hasn’t passed the test?
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.
mmm in the conditional
if(celda === " " || index+1 === i.length)
if the array ends or is a white space, the 2nd count is replace with the actual count (if the actual count is longer than the 2nd)