Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda