My question is can we use the Document.write in a loop? As the following code doesn't works well. Guess what wrong in it!

<script type="text/javascript">
var d = 1;
var p;
while (days <= 4){
p = prompt("value of p?",0);
document.write("the value of p" + p);
p=p+p;
d++;
  };

</script>

Well the first problem is that I don't see where "days" is defined anywhere in your script.

Also is p being treated like a number?

Use f12 in your browser to load the console. You can see your errors and warnings there.

Member Avatar for [NOPE]FOREVER

JorgeM is right, you do not have a defined 'days' variable So the loop wont even start

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.