Can anyone spot the bug?

This code doesn't work. It The document.clear method should be erasing the
screen but instead of getting each number replacing the previous, the
numbers appear below the previous, like:
10
9
8
7
6
5
4
3
2
1

        function sleep(duration) {
          startTime=new Date()
          var msToWait=1000*duration
          endTime=startTime.getTime()+msToWait
          newTime=new Date()
          var nt1=newTime.getTime()
          while (nt1<endTime) {
            newTime=new Date()
            nt1=newTime.getTime()
          }
        }
        
        function Countdown() {
          prefix="<center><h1>"
          suffix="</h1></center>
          for (var i=10; i>0; i--) {
            document.open()
            document.clear()
            document.close()
            document.open()
            document.write(prefix + i + suffix)
            document.close()
            sleep(1)
          }
        }

I also tried this, using a text box in a form:

        function Countdown() {
          document.open ("text/html")
          document.write("<form name=cntdn action=surpr2.html
method=get>Launch in<input type=text maxlength=2 name=cdtxt> seconds.</form>")
          document.close()
          for (var i=10; i>0; i--) {
            document.open()
            document.cntdn.cdtxt.value=i
            document.close()
            sleep(1)
          }
        }

but it performs even worse. I get "Launch in" and nothing else while it
counts down the ten seconds even though the document.close should ensure
it redraws. When it finishes I see the text box with "1" in it and the
"seconds." Then Netscape crashes with an "invalid page fault".
I can't see anything wrong with these...have I found bugs in Netscape or
something?
--
    .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
 -()  <  circles, and bark is not smooth, nor does lightning travel in a
    `*'  straight line."    ,------------------------------------------------
         -- B. Mandelbrot  |  Paul Derbyshire (PGD) ao950@freenet.carleton.ca

Received on Thursday, 11 April 1996 02:50:03 UTC