Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

460
Views
How can I make an if statement that asks, if the number equals to 8 to the power of n (8^n)?

I want to do an if statement that looks something like this:

(n is a natural number)

if (number == 8^n) {
  // Code...
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use Math.pow(x, y);

Example:

function check(number,n){
  let r = Math.pow(8, n);
  if (number==r)
    //Do something
}
about 4 years ago · Juan Pablo Isaza Report

0

var n=parseInt(prompt("Enter N:"));
var _number =parseInt(prompt("Enter Number:"));
if(!isNaN(n) && !isNaN(_number))
{
  if(_number == Math.pow(8, n))
    console.log("Equal");
  else
    console.log("Not Equal");
}else
   console.log("Invalid N / Number");

Or

var n=parseInt(prompt("Enter N:"));
var _number =parseInt(prompt("Enter Number:"));
if(isNaN(n))
   console.log("Invalid N");
else if(isNaN(_number))
   console.log("Invalid N");
else
{
  if(_number == Math.pow(8, n))
    console.log("Equal");
  else
    console.log("Not Equal");
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!