How to prevent Chrome from displaying an alert before all previous commands have been executed?

This function works well in IE and Firefox. But with Chrome, the alert is displayed before all the other commands have been executed, which is a nonsense because the user doesn’t even have a chance to see what happened before the alert comes on. Of course the alert is freezing everything else, but it comes too quick. How do I prevent this behaviour. Here’s my code:
function crash(cr)
cj=cj+1; var j=document.images[cj]; B.src=“pxtransp.gif”; b.width=1; b.height=1; j.src=“X.gif”;“absolute”;;; j.width=29; j.height=29;

You could wrap alert in setTimeout:

setTimeout(() => {
}, 0)

Thanks Jenov. It works fine with a 500ms timeout. Just what I needed.