JavaScript JavaScript Basics (Retired) Introducing JavaScript Your First JavaScript Program

Monika Agarwal
Monika Agarwal
55 Points

the alert does not work as per the video.in my case both the alerts popped simultaneously one after the other

as per the video the sequence of the statements should be first alert then page and then alert .

Luis Onate
Luis Onate
13,222 Points

Could you paste your code so we can see it? If you paste your code between sets of 3 backticks (```) we'll be able to see if more clearly.

4 Answers

Steven Parker
Steven Parker
207,979 Points

It could be the browser.

Not long ago, it was common for browsers to display page info while the JavaScript was running, but now it's more common for the browser to wait until the JavaScript program finished before displaying the rendered page.

So it would make sense that with modern browsers, both alerts would be displayed as the program runs, but anything written to the page would not be seen until the program ended. The browser used in the video probably had a different behavior.

Andrew Phythian
Andrew Phythian
19,747 Points

The latest version of Safari appears to do precisely this. Both alerts appear before the document.write part is written to the page.

same with me i'm using chrome on w10

Steven Parker
Steven Parker
207,979 Points

As I said, that's the way browsers work now.

got that ;)