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

115
Vistas
How to use chessboard positions in an if-else statement for chessboard.js

I am trying to create a function that uses an if-statement to check if a chessboard is in a specific position (this one I am using start) using the chessboard.js library

I tried using this code that compares the board's position property to the position I want using the object and FEN string but both doesn't work.

  if (board.position == {a1: "wR", a2: "wP", a7: "bP", , a8: "bR", b1: "wN", b2: "wP", b7: "bP", b8: "bN", c1: "wB", c2: "wP", c7: "bP", c8: "bB", d1: "wQ", d2: "wP", d7: "bP", d8: "bQ", e1: "wK", e2: "wP", e7: "bP", e8: "bK", f1: "wB", f2: "wP", f7: "bP", f8: "bB", g1: "wN", g2: "wP", g7: "bP", g8: "bN", h1: "wR", h2: "wP", h7: "bP", h8: "bR") {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');
   if (board.position == 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR') {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');

I even tried comparing it to 'start'

   if (board.position == 'start') {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Based on the docs, board.position is a function. You want to compare against the output of that function, not the function itself:

if (board.position('fen') == 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR')

(Comparing objects for equality is more complicated; I'd suggest sticking with the FEN strings.)

about 4 years ago · Juan Pablo Isaza Denunciar
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