fixed for loop, added if statement to find longestWord