Math.pow(base, exponent);
Math.pow(2, 4);
// Outputs 16
// The same as going 2^4, 2 to the power of 4
function solution(n) {
if (n === 1) {
return true;
}
for (let i = 2; i < n; i++) {
let power = i;
while (power < n) {
power *= i;
}
if (power === n) {
return true;
}
}
return false;
}
base ** exponent
// Math.pow()
// The Math. pow() method returns the value of x to the power of y (xy).
// EXAMPLE : 1
let powerOf = Math.pow(2,5);
console.log(powerOf);
// OUTPUT: 32
// EXAMPLE : 2
let powerOf2 = Math.pow(-2,5);
console.log(powerOf2);
// OUTPUT: -32
// EXAMPLE : 3
let powerOf3 = Math.pow();
console.log(powerOf3);
// OUTPUT: NaN
var x = parseInt(prompt("Enter the base: "))
var y = parseInt(prompt("Enter the power: "))
var value = parseInt(Math.pow(x, y))
console.log(value)
Math.pow(8, 2);