If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I don't know why you're showing this code given that (A) it's not JavaScript and (B) it doesn't calculate a result of 3⁷ (2187). The result is 243 or 3 / 9 / 27 / 81 / 243 depending on how it's interpreted.

Originally Posted by Alien_Coder

There was a similar question which required me to calculate 3^7, here is my solution:N=1 Y=3
while N ≦ 7 do
Y=Y x Y
N = N + 1
end while
print Y

Ditto for this code except that the wrong result is well over 3⁷.

Originally Posted by Alien_Coder

Is it possible to write the code using 1 while statement?

That would be the most efficient way to write it. Doing it that way would require that you use the Math.pow(base, exponent) method.

I have a feeling that you're being asked to calculate each result without the use of built-in mathematical functions though. Doing so would require using two while statements as required by the problem statement.

For every complex problem, there is an answer that is clear, simple, and wrong.

Even if this is homework, you will not be able to present this to your instructor
unless you can explain the push() statement, but at least you will be able to
see the correct syntax to create a trial script for further testing.

I'm stuck in a problem, I want to write a simple code that calculates: 1^1,2^2,3^3,4^4,5^5 using two WHILE statements only, how can I achieve such a thing?

Well, since the cat's out of the bag, here's the "simple" (not really) code I wrote using JavaScript, XHTML, and MathML. I'm sure your instructor will be enthused to hear you relate how you mastered DOM-based math.