Never use document.write(). The official HTML spec actually contains a warning against using it. If you haven't learned proper DOM manipulation yet, use document.innerHTML, but that too is considered bad.
Beyond this matter, your code is missing a couple of things. First is that it never goes to the next line, so all the asterisks will appear on the same line. If you add proper code to go to the next line, you have to do that at the right place. The typical solutions are to use nested loops or the string repeat method. Other solutions are possible, but those are less intuitive.