Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read n; log yes if it is a power of two, else no.
Input. Integer ≥ 1.
Output. yes or no.
Examples
Input
8
Output
yes
Input
6
Output
no
Hint
- n > 0 && (n & (n - 1)) === 0
Show correct code
Peek only after you have tried. You can still Check your own version.
const n = Number(readLine());
console.log(n > 0 && (n & (n - 1)) === 0 ? 'yes' : 'no');
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.