Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
How not to create multiple IF with multiple different variables - Jquery/Javascript

enter image description here

This is a Drag and Drop function so the user leaves the items in the correct fields a victory message should appear and disable a button. Even if the user completes the 5 options as wrong, the button should also be disabled but a "game over" message should appear. Is there any more way to validate when it's easy instead of having to create an IF for every wrong drag.

function buttonDisabled(){
    // TRUE
    if( $('#items-10').has('#item-1').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
     {$('#next').prop("disabled", false);}
  // False
  if( $('#items-10').has('#item-2').length == 1 && $('#items-7').has('#item-1').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-3').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-1').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-4').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-1').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-5').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-1').length == 1 )
    { $('#next').prop("disabled", false);}
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda