Add nullish coalescing to multiple articles, refactor operators, renumber the chapter
This commit is contained in:
parent
175aefa0b8
commit
8a13c992d6
54 changed files with 386 additions and 183 deletions
21
1-js/02-first-steps/15-function-basics/4-pow/solution.md
Normal file
21
1-js/02-first-steps/15-function-basics/4-pow/solution.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
```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) );
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue