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">
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"));