up
This commit is contained in:
parent
83b93e5992
commit
9ad9063d00
742 changed files with 884 additions and 779 deletions
23
1-js/02-first-steps/14-function-basics/4-pow/solution.md
Normal file
23
1-js/02-first-steps/14-function-basics/4-pow/solution.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
```js run demo
|
||||
function pow(x, n) {
|
||||
let result = x;
|
||||
|
||||
for (let i = 1; i < n; i++) {
|
||||
result *= x;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
let x = prompt("x?", '');
|
||||
let n = prompt("n?", '');
|
||||
|
||||
if (n <= 1) {
|
||||
alert(`Power ${n} is not supported,
|
||||
use an integer greater than 0`);
|
||||
} else {
|
||||
alert( pow(x, n) );
|
||||
}
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue