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

153
Views
The time required to destroy a building in the browser game is calculated incorrectly
// Number of rockets launched per second.
const rocketSpeed = 1;

// The amount of damage dealt by rocket.
const attackDamage = 60;

// The amount of hit points of the building.
const buildingHitPoints = 1000;

// The number of rockets required to destroy the building.
const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

// The time it takes to destroy the building.
const requiredTime = numberOfRockets * rocketSpeed;

If the rocketSpeed is more than one second, then I get the correct value.

For example: const requiredTime = 17 * 1;

But if you specify a rocketSpeed less than 1 second, then the value is incorrect:

For example: const requiredTime = 17 * 0.625; // 10.625

0.625 is the number of rockets fired per second. That is, 1 rocket will be launched in about ~ 1.2 seconds.

I've tried different options by type: const requiredTime = 17 + (17 - 37.5%); (37.5% because: 1000 - 625 = 375. 375 is 37.5% of 1000), but it doesn't work.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Number of rockets launched per second is better thought of as a frequency than a "speed".

Frequency f is f = 1/T where time is T, so T = 1/f

Maybe rename rocketSpeed to rocketFrequency and make a new variable timeBetweenRockets with
const timeBetweenRockets = 1 / rocketFrequency.

Then the last line of code will be more selfexplaining

const requiredTime = numberOfRockets * timeBetweenRockets

about 4 years ago · Juan Pablo Isaza Report

0

You have the calculation the wrong way round. If you try values greater than 1 then you'll see it takes longer: 1 rocket per second (r/s) results in 17 seconds. 2 r/s results in 34 seconds and 0.5 r/s gives 10.625 seconds.

const calculate = rocketSpeed => {

  // The amount of damage dealt by rocket.
  const attackDamage = 60;

  // The amount of hit points of the building.
  const buildingHitPoints = 1000;

  // The number of rockets required to destroy the building.
  const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

  // The time it takes to destroy the building.
  const requiredTime = numberOfRockets * rocketSpeed;
  
  return requiredTime;
}
 
console.log(`Time for 1 rocket/s: ${calculate(1)}`);
console.log(`Time for 2 rocket/s: ${calculate(2)}`);
console.log(`Time for 0.625 rocket/s: ${calculate(0.625)}`);

If you instead divide numberOfRockets by rocketSpeed you'll get the right answers.

const calculate2 = rocketSpeed => {

  // The amount of damage dealt by rocket.
  const attackDamage = 60;

  // The amount of hit points of the building.
  const buildingHitPoints = 1000;

  // The number of rockets required to destroy the building.
  const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

  // The time it takes to destroy the building.
  const requiredTime = numberOfRockets / rocketSpeed;
  
  return requiredTime;
}

console.log(`Time for 1 rocket/s: ${calculate2(1)}`);
console.log(`Time for 2 rocket/s: ${calculate2(2)}`);
console.log(`Time for 0.625 rocket/s: ${calculate2(0.625)}`);

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!