Added document.write() to loop