I have the following exercise:
** The 3 coordinates of 3 vectors in space are read (v1, v2, v3). Make an app in javascript that shows the following:
The magnitude of each vector
The product bridge from v2 to V1
The sum of v1 + v2
The difference of v3-v1
The distance between v2 and v1 **
This I have to do in javascript and I tried the following:
<script>
var valuesVector = [];
function Vector(i,j,k){
this.i = i;
this.j = j;
this.k = k;
}
function obtenerValores(){
var i = document.getElementById('i-1').value;
var j = document.getElementById('j-1').value;
var k = document.getElementById('k-1').value;
return i;
return j;
return k;
}
function CreaVector(){
var vector = new Vector(obtenerValores());
valuesVector.push(vector);
mostrarCalculo();
}
function mostrarCalculo(){
var result = "";
for(var i=0; i<valuesVector.lenght; i++){
result+= 'i:' + valuesVector[i].i +
'j:'+ valuesVector[i].j +
'k:'+ valuesVector[i].k + '\n';
}
document.getElementById('resul').innerText = result;
}
</script>
<h4>VECTOR V1</h4>
<form action="" class="form-horizontal">
<input class="form-control" type="text" id="i-1">
<input class="form-control" type="text" id="j-1">
<input class="form-control" type="text" id="k-1">
<button class="btn btn-primary" onclick="obtenerValores();
CreaVector();" type="button">Calcular</button>
</form>
<h4 id="resul"></h4>
This is what I have tried without obtaining any results, for now I want to show the data that I have entered in the input, but it does not show me anything. And I would also like to know that since there are 3 vectors V1 V2 and V3 and each one has to have 3 data inside it, I would have to do a different function to obtain and calculate the data for each of the vectors? I need help with this, I do not know much about javascript and I'm very lost.