Finished script using for loop and indexOf