if you see this line
y = "" + x + "<br>"
you are keep on overwriting the variable
y
from
0 to Infinity so at the end of the loop the last value will be stored to the variable which is
Infinity
You should append the value to variable to see the entire loop result.
use
y += x + "<br>"