Please see the comment on code below to see the problem.

<html>
	<head>
		<title>Sequence: x ^ n -1</title>
	</head>
	<body>
		<script type = "text/javascript">
		var sqn;
		var pow=1;
		var pans=1;
		do {
			sqn = prompt("Enter Sequence: ");
		}while(sqn<0);
		var psqn;
		psqn=parseFloat(sqn);
		if (psqn==0){
			document.write("0");
		}
		else if (psqn>0){
			document.write("9<font color=red> --- </font>");
			for (x=1;x<psqn;x++){
				pans=1;
				for (y=0;y<=pow;y++){
					pans = pans*10;
				}
				--pans;//this line does not work when user input is greater than 15
				pow++;
				document.write(pans + "<font color=red> --- </font>");
			}
		}
		</script>
	</body>
</html>

line 21 - You put pans at 1 every time the loop is repeated.

~G

commented: sorry, not helpful. +0

Thanks for the effort of posting your VERY helpful answer but I guess that doesn't solve the issue. I intentionally assigned 'pans' to hold a value of '1' every time the loop is repeated to make sure that it will hold a correct value every time a new loop begins.

Additional info: The user inputted value (sqn) determines how many times the equation x^n-1 will be repeated. Example, if user input is 1 then:

10^1 - 1, the program will print "9".

If user input is 3, then:

10^1 - 1, the program loops, 10^2 -1, the program loops for the last time, 10^3-1.
The printed output would be:

9 --- 99 --- 999 ---

the sequence works if user input is !< 0 && <=15. It begins to fail when user input is >=16.

That is an expected result. On most 32-bit platforms the largest javascript integer is 2^31-1 and the maximum precision of a floating point number is 15 digits.

I see... Thanks...

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.