add new counter variable j that increments only when a word index matches a string index; add extra conditional to while loop that requires word[j] exists