Good morning! Here's our prompt for today.
Given an integer num
, write a method to determine if it is a power of 3.

The method will be called as follows:
JAVASCRIPT
1console.log(powerOfThree(9));
2// true
3
4console.log(powerOfThree(7));
5// false
Constraints
- The given would be a non zero positive integer in the range between
1
and2147483647
- Expected space complexity :
O(logn)
- Expected time complexity :
O(1)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
34
console.log('PASSED: ' + 'powerOfThree(729) should be true');
var assert = require('assert');
​
function powerOfThree(num) {
// Fill in this method
return num;
}
​
console.log(powerOfThree(9));
console.log(powerOfThree(7));
​
try {
assert.equal(powerOfThree(9), true);
​
console.log('PASSED: ' + 'powerOfThree(9) should be true');
} catch (err) {
console.log(err);
}
​
try {
assert.equal(powerOfThree(7), false);
​
console.log('PASSED: ' + 'powerOfThree(7) should be false');
} catch (err) {
console.log(err);
}
​
try {
assert.equal(powerOfThree(729), true);
​
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Tired of reading? Watch this video explanation!
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's how we would solve this problem...
How do I use this guide?