- #1

- 127

- 0

Code:

```
var power = function(exponent, base){
if (exponent === 0){
return 1;
}
};
power();
```

It does not work, ca anyone tell why?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Java
- Thread starter mindauggas
- Start date

- #1

- 127

- 0

Code:

```
var power = function(exponent, base){
if (exponent === 0){
return 1;
}
};
power();
```

It does not work, ca anyone tell why?

- #2

Mark44

Mentor

- 35,993

- 7,925

Code:`var power = function(exponent, base){ if (exponent === 0){ return 1; } }; power();`

It does not work, ca anyone tell why?

You are not calling your function correctly.

1. The power function has two parameters. You are calling it with no parameters.

2. The power function returns a value, so you need to store or otherwise use the return value.

Code:

`var retValue = power(0, 10);`

Also, you don't need to use === in your comparison, since you're just comparing numbers, not objects. The == operator should work just fine.

Share:

- Replies
- 12

- Views
- 3K