Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

JS is not executing in order what sir says why?

Dave McFarland sir why mine is not same as your output

alert("Hello world"); document.write("<h1>Hello world</h1>"); alert();

as sir says that JS engine execute it in one by one order but in my chrome browser first alert comes that says "Hello world" and then i click on OK button H1 tag not execute another alert comes and after second alert's executes and i click on its OK button H1 then appears why so in sirs browser alert comes h1 comes and alert comes why my is not same

Jarratt Isted
Jarratt Isted
2,437 Points

Pretty sure it's because you're executing the alert(); function more than once. It might be helpful to write the code on separate lines for clarity, too.

If you want your code to run an alert and then write to the document, try this:

alert("Hello world");
document.write("<h1>Hello world</h1>");

You don't need to use the alert(); function twice.

Steven Parker
Steven Parker
208,474 Points

But Jarratt, running the alert both before and after the write was the purpose of the demonstration. :wink:

7 Answers

Steven Parker
Steven Parker
208,474 Points

:point_right: Modern browsers work a bit differently than the one in the video.

Most browsers now display the rendered page only after the initial JavaScript has completely finished.

The browser in the video displayed the page while the JavaScript was still running.

This should probably be mentioned in the "teacher's notes". You might want to report this as a bug using the Support page - it may even get you a "special Exterminator badge".

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Sorry about that! Thanks Steven Parker for steering j s in the correct direction. I'm in the middle of updating several videos in this course that suffer from this same problem, so a fix should be in sometime (relatively) soon -- holidays are here, so probably not until beginning of January.

I like how teachers can easily comment here. Very nice.

Gabor Galantai
PRO
Gabor Galantai
Pro Student 17,247 Points

Dave McFarland how is the updating of the videos going? I still see this problem.

ywang04
ywang04
6,749 Points

Also the same issue.

Jon Speake
Jon Speake
3,466 Points

Still same issue.

Same here

Dave McFarland Still seeing it here as well.

Nick Post
PRO
Nick Post
Pro Student 3,155 Points

Same issue...... came here and it said this bug was to be worked out in January? Was that of 2017?