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

207
Vistas
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 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