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

86
Views
Quiero que mi javascript pase a la siguiente declaración si la primera se evalúa como VERDADERA

Quiero verificar si hay valores negativos y, si los hay, cambiarlos a su valor predeterminado.

 for (i = 0; i <= 1; i++) { //I want this to run this statement once and if its true perform all the functions and move to the next one if (h1 < 0 || h2 < 0) { alert("negative number is not acceptable here"); document.getElementById("up1").value = document.getElementById("up1").defaultValue; document.getElementById("q1").value = document.getElementById("q1").defaultValue; document.getElementById("tot1").value = document.getElementById("tot1").defaultValue; Total1 = 0.00; continue; } else if (h3 < 0 || h4 < 0) { alert("No Negative here as well") document.getElementById("up2").value = document.getElementById("up2").defaultValue; document.getElementById("q2").value = document.getElementById("q2").defaultValue; document.getElementById("tot2").value = document.getElementById("tot2").defaultValue; continue; } //I have a let Total1 & Total2 variables at the beggining of the code set to zero // Total2 = h3 * h4; }

Hola chicos, de todos modos hay que continuar con la siguiente declaración else if si la primera declaración IF se evalúa como VERDADERA y ejecuta todas las funciones en ella. Actualmente, si la primera instrucción IF se evalúa como verdadera, realiza todas las funciones y finaliza el ciclo. Quiero que verifique cada variable en busca de un negativo sin repetir el código nuevamente.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Hay dos casos para su problema.

  1. Desea ejecutar el segundo bloque solo si el primer bloque if es verdadero.
  2. Desea ejecutar el segundo bloque, ya sea que el primer bloque sea verdadero o falso

primer caso

 isFirstBlockTrue = false if (h1 < 0 || h2 < 0) { isFirstBlockTrue = true /* rest of your code */ } if(isFirstBlockTrue){ if (h3 < 0 || h4 < 0) { /* rest of your code */ } } /* rest of your code */

segundo caso

 if (h1 < 0 || h2 < 0) { /* first block code */ } if (h3 < 0 || h4 < 0) { /* second block code */ }

Nota: no use continuar, de lo contrario se saltará la iteración

about 4 years ago · Juan Pablo Isaza Report

0

Si desea ejecutar el segundo bloque solo si el primer bloque si es verdadero:

 if (h1 < 0 || h2 < 0) { /* Your code */ if(h3 < 0 || h4 < 0){ /* rest of your code */ } }
about 4 years ago · Juan Pablo Isaza Report

0

Solo necesita dos sentencias if lineales.

 for (i = 0; i <= 1; i++) { //I want this to run this statement once and if its true perform all the functions and move to the next one if (h1 < 0 || h2 < 0) { alert("negative number is not acceptable here"); document.getElementById("up1").value = document.getElementById("up1").defaultValue; document.getElementById("q1").value = document.getElementById("q1").defaultValue; document.getElementById("tot1").value = document.getElementById("tot1").defaultValue; Total1 = 0.00; } if (h3 < 0 || h4 < 0) { alert("No Negative here as well") document.getElementById("up2").value = document.getElementById("up2").defaultValue; document.getElementById("q2").value = document.getElementById("q2").defaultValue; document.getElementById("tot2").value = document.getElementById("tot2").defaultValue; } Total2 = h3 * h4; }
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!