Dont understand problem

I dont understand why the function for the exponent isn’t working
https://codepen.io/coderkoji/pen/KKaeyJK
note: you’ll have to scroll down until the //6 appears

Why are you using a loop to do exponentiation? Are you not allowed to say something like
Math.pow(base, raise)

For this project im supposed to do it with loops.

You currently have three issues with your exponent function.

  1. You are returning answer after the first iteration.
  2. You start answer at the value 2 for some reason.
  3. Your for loop condition is off by 1.

Hello can you explain to me what this: You are returning answer after the first iteration means please

Whenever a return statement is executed, the function is exited immediately.

Thanks so much I finally figured it out :grinning:

What does your final code look like?

Here:
const exponent = (base,power) => {
let answer = base;
for (let i = 0; i < power-1; i++) {

answer *= base;

}
return answer;
}

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.