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.

- You are returning
`answer`

after the first iteration. - You start
`answer`

at the value`2`

for some reason. - 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

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.