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

133
Views
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 answers
Answer question

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 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!