Pass value from one to another for

0

I have these 2 cycles for , I need to pass the value of the variable disxd of the first cycle for to the variable disxd of the second < em> cycle for

var distancia, aux = 0;
arrText2.splice(0, 1);
arrText1.pop();
var disxd = [];
var distanciaCentro, aux8 = 0;
for (var i = 0; i < arrText.length; i++) {
  parseFloat(arrText[i]);
  distancia = (arrText[i] + aux) / escala;
  aux = aux + arrText[i];
  var altos = 68;
  var disxd = (aux - 250) / escala;
  var image = document.getElementById('screem');
  ctx.drawImage(image, 80 + disxd, 67);

}
//Centro de sanitarios
for (var i = 0; i < arrText1.length; i++) {
  parseFloat(arrText1[i]);
  if (i === 0) {
    distanciaCentro = arrText1[i] + (arrText2[i]) / 2
  } else {
    if (i => 1) {
      distanciaCentro = (arrText1[i]) / 2 + (arrText2[i]) / 2
    }
  }
  var disxd = (aux - 250) / escala;
  /*Info Ancho cubículo individual*/
  ctx.font = '16px Arial';
  ctx.fillText(distanciaCentro, 95 + disxd, 120);
}
    
asked by Eduard Zora 21.04.2017 в 21:46
source

1 answer

1

If you need to use the value that was left after leaving the first for, do not declare it again.

Instead of

 var disxd = (aux - 250) / escala;

Saves its value in another variable

 var disxd2 = disxd;

Or in any case, you assign what you already had before continuing with the calculation

disxd += (aux - 250) / escala;

I hope you serve

    
answered by 21.04.2017 / 21:52
source