You're accidentally incrementing str
when you should be incrementing i
:
for(var i=0;i<str.length;str++){//for loop that checks each letter
^---// replace str with i
I don't know if the rest of your code works, but this would explain that particular error.