Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/04/2016, 16:53
Avatar de Fernand0
Fernand0
 
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: ¿Cómo recupero el resultado de un condicional en el mismo código?

Código Javascript:
Ver original
  1. var num1 = document.getElementById('num1').value;
  2. var num2 = document.getElementById('num2').value;
  3.  
  4. var num2por5 = num2 * 5;
  5. var num2por10 = num2 * 10;
  6. var num2por15 = num2 * 15;
  7.  
  8. var resultado = document.getElementById('resultado');
  9.  
  10. if (num1 <= num2por5){
  11.     resultado.value = num1 * 1.20;
  12. }
  13. else if (num1 > num2por5 && br <= num2por10){
  14.     resultado.value = num1 * 1.30;
  15. }
  16. else if (num1 > num2por10 && br <= num2por15){
  17.     resultado.value = num1 * 1.40;
  18. }
  19.  
  20. function modificar(valor, operacion) {
  21.     if(operacion == "+") resultado.value += valor;
  22.     if(operacion == "-") resultado.value -= valor;
  23.     if(operacion == "*") resultado.value *= valor;
  24.     if(operacion == "/") resultado.value /= valor;
  25.     // etc
  26. }
  27.  
  28. modificar(3, "+");