Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda