Good evening! Here's our prompt for today.
Given a number x
and an integer n
, find the value of x
raised to the power n
( xn ).

For example, consider the following two numbers,
SNIPPET
1x = 2.1, n = 3
If the number 2.1
is multiplied by itself 3
times, then the answer is 9.261 (rounded to the nearest 100), which is 2.1
raised to the power 3
.
Constraints
- -100.0 < x < 100.0
- -231 <= n <= 231-1
- -104 <= xn <= 104
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
35
var assert = require('assert');
​
function powN(x, n) {
return;
}
​
​
try {
assert.equal(powN(2, 10), 1024);
console.log('PASSED: ' + "`powN(2, 10)` should return `1024`");
} catch (err) {
console.log(err);
}
​
try {
assert.equal(powN(2.1, 3), 9.261000000000001);
console.log('PASSED: ' + "`powN(2.1, 3)` should return `9.261000000000001`");
} catch (err) {
console.log(err);
}
​
try {
assert.equal(powN(2, -2), 0.25);
console.log('PASSED: ' + "`powN(2, -2)` should return `0.25`");
} catch (err) {
console.log(err);
}
​
try {
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
We'll now take you through what you need to know.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.