Created
May 14, 2016 06:27
-
-
Save cruzick/4a8f144fc48b6951346f752bf1efd803 to your computer and use it in GitHub Desktop.
Question about str[] in a loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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