Skip to content

Instantly share code, notes, and snippets.

@cruzick
Created May 14, 2016 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cruzick/4a8f144fc48b6951346f752bf1efd803 to your computer and use it in GitHub Desktop.
Save cruzick/4a8f144fc48b6951346f752bf1efd803 to your computer and use it in GitHub Desktop.
Question about str[] in a loop.
function findLongestWord(str) {
var length = 10;
var biggest = 0;
var j = 0;
if (str[j] != " ") { // THIS WORKS AS EXPECTED
biggest += 1;
}
for (var i = 0; i > str.length; i++) { // THIS DOESN't WORK.
if (str[i] != " ") { // IF I REMOVE THE ABOVE IF STATEMENT
biggest += 1; // BIGGEST = 0
}
}
return biggest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment