added typeof and while loop to make only vacant squares clickable