Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
JavaScript equation returning stinky NaN value
var shaftDepth = 1;
var nextShaftDepth = ((maxThreshold - shaftDepth) / 20) + shaftDepth;
var maxThreshold = 10;

The equation for nextShaftDepth spits out an NaN value.

For context, I'm planning to have an "upgrade" in my game which decreases the distance of "shaftDepth" to "maxThreshold" by 5%. To do this, shaftDepth = nextShaftDepth after the formula is done.

"nextShaftDepth" is expected to be equal to 1.45, but instead it just returns an NaN value. Am I doing approaching this wrong or is my syntax incorrect? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

var is hoisted, it will be undefined as you're trying to access it before the declaration , change your code to

var shaftDepth = 1;
var maxThreshold = 10;
var nextShaftDepth = ((maxThreshold - shaftDepth) / 20) + shaftDepth;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda