en.javascript.info/1-js/02-first-steps/14-function-basics/4-pow/solution.md
Ilya Kantor f72405a263 minor
2019-07-29 18:02:18 +03:00

21 lines
297 B
Markdown

```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 a positive integer`);
} else {
alert( pow(x, n) );
}
```