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

205
Visualizações
How to determine if a chessboard is in a specific position in chessboard.js

I am making a website that revolves around chess and embedding interactive chessboards using the chessboard.js library.

I am trying to create a function that will tell if the chessboard is in a specific position that is called when an HTML button is pressed via browser alerts. The problem is that the alert appeared when the webpage is loaded but doesn't when the button is pressed. Here is the code:

  <div id="board1" style="width: 400px"></div>
  <button id="clearButton">Clear Board</button>
  <button id="checkAnswer">Check Answer</button>
  <button id="showSolution">Show Solution</button>
  
  <script>
    var board = Chessboard('board1', {
      draggable: true,
      dropOffBoard: 'trash',
      sparePieces: true
    })

    $('#clearButton').on('click', board.clear)
    $('#showSolution').on('click', board.start)
    $('#checkAnswer').on('click', checkAnswer())

    function checkAnswer() {
      if (board.position == 'start') {
        alert('The board is in the start position');
      } else {
        alert('The board is not in the start position')
      }
    }
    </script>
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