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

289
Views
Condición if else me muestra los resultados al revés. ¿Que esta pasando?

He hecho una condición if else simple donde debería mostrar cuál es el mayor número de las dos entradas ingresadas, pero me muestra el valor opuesto al esperado. ¿Que esta pasando? ¡Gracias por adelantado!

HTML:

 <input type= "text" id="texto"> <input type= "text" id="texto2"> <button type="submit" id="enviar">Enviar</button>

JS:

 const texto = document.getElementById('texto'); const texto2 = document.getElementById('texto2'); const send = document.getElementById('send'); send.addEventListener('click', mayorque) function mayorque() { if (texto > texto2){ alert('Input 1 is greater than input 2') } else { alert('Input 2 is greater than input 1') } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Algunos problemas.

Cuando configura la variable texto en carga, está tomando el valor de la entrada en carga. Deberá obtener el valor en la función.

Usar algo como parseFloat convertirá el valor a un valor numérico. Flotante permitirá puntos decimales.

 let texto = document.getElementById('texto'); let texto2 = document.getElementById('texto2'); const send = document.getElementById('send'); send.addEventListener('click', mayorque) function mayorque() { texto = parseFloat(texto.value); texto2 = parseFloat(texto2.value); if (texto > texto2) { alert('Input 1 is greater than input 2') } else { alert('Input 2 is greater than input 1') } }
 <input type="text" id="texto"> <input type="text" id="texto2"> <button type="submit" id="send">Enviar</button>

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!