Tell us what’s happening:
hi can someone tell me why we the variable var longestWord=0; equals zero, what is the logic behind it?
Your code so far
function findLongestWord(str) {
//Primero añadimos dentro del parentesis de .split(" ") comillas separadas con espacio para que queden las palabras divididas por comillas
var strSplit=str.split(" ");
//segundo: inicia una variable que contendrá la longitud del string mas largo.
var longestWord=0;
//creamos un for loop
for (var i =0; i< strSplit.length; i++){
if (strSplit[i].length>longestWord){
longestWord= strSplit[i].length;
}
}
return longestWord;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/find-the-longest-word-in-a-string