Javascript repeat function n times. Currently, it doesn’t wait, i.