开发者

Javascript order execution of prompt and document.writeln statements

I am trying to write a program that iteratively solves a problem with user input. It is something like trying to guess a user's number between 0 and 100 using binary search.

So the program spits something out (in the form of document.writeln statements); then asks the user for a new input (using prompt()); does some more crunching and spitting out until eventually it terminates. Here is my problem:

The program does not execute the document.writeln statements until it has executed all of the prompt statements. The rest of the statements execute in proper order.

I'd really appreciate some help on understanding why this this happening. I know that Javascript has a peculiar notion of executi开发者_运维百科on order and perhaps it is doing this because it likes to do the prompt()'s first because they are alerts, but I still don't get it.

thanks


You might want to try appending some text onto the contents of a <div>. document.writeln has some legacy problems that you're likely to run into if you continue down this path.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜