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

134
Visualizações
Vector resultant

I'm trying to make a resultant of 3 vectors. But when I put a number, return NaN instead.Can someone explain?

var vectoro = document.getElementById("f1");
var vectortw = document.getElementById("f2");
var vectorth = document.getElementById("f3");
var d1 = document.getElementById("d1");
var d2 = document.getElementById("d2");
var d3 = document.getElementById("d3");
var hasil = document.getElementById("hasil");

function prosessatu(){
let f1 = vectoro * Math.cos(d1.value * Math.PI / 180).toFixed(2);
let f2 = vectortw * Math.cos(d2.value * Math.PI / 180).toFixed(2);
let f3 = vectorth * Math.cos(d3.value * Math.PI / 180).toFixed(2);
let fsino = vectoro * Math.sin(d1.value * Math.PI / 180).toFixed(2);
let fsintw = vectortw * Math.sin(d2.value * Math.PI / 180).toFixed(2);
let fsinth = vectorth * Math.sin(d3.value * Math.PI / 180).toFixed(2);
let sigmafx = Math.pow((f1 + f2 + f3), 2);
let sigmafy = Math.pow((fsino + fsintw + fsinth), 2);
hasil.value = Math.sqrt((sigmafx + sigmafy))
}
vectoro.oninput = prosessatu;
d1.oninput = prosessatu;

vectortw.oninput = prosessatu;
d2.oninput = prosessatu;

vectorth.oninput = prosessatu;
d3.oninput = prosessatu;

I'm using <input type = "numbers">

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

0

The type of your input should be number, not numbers

See documentation for number input type

However my understanding is that type attribute is only used by browser to validate the field. When retrieving its value using javascript, you will get a String.

So you need to parse it, e.g

var d1 = Number.parseFloat(document.getElementById("d1"));
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