The Power Function

EasyAcc. 93.7%
+20 XP 8

Manual Exponentiation

You need to calculate the result of base raised to the exponent power manually.

The Assignment

Your function receives parameters base and exponent.

  1. Initialize result to 1.
  2. Use a loop to multiply result by the base for a total of exponent times.
  3. After the loop, print the result.

[!NOTE] Any number to the power of 0 is 1.

01EXAMPLE 1

Inputbase=2, exponent=3
Output8

Explanation: 2 * 2 * 2 = 8

Constraints

  • Do not use Math.pow() or the ** operator.
  • Use a standard for or while loop.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

base2
exponent3

Expected Output

8

Click RUN to test your solution