He estado tratando de escribir un programa de ajedrez con HTML, CSS y Javascript. Parece que no puedo obtener la función onclick para que funcione el botón "JUGAR COMO BLANCO". Revisé mi sintaxis en la parte de Javascript y creo que me parece bien. ¿Hay algo que esté haciendo mal con el código?
Aquí está el código:
let info = document.getElementById("info"); function playAsWhite() { info.innerHTML = "the message I want to output"; } <h1 id="info">Playing as White:</h1> <h1>Best move:</h1> <p>NaN</p> <input type="text" placeholder="Your input:" id="inputId1"> <button onclick="player1Turn()">Enter</button> <input type="text" placeholder="Enemy input:" id="inputId2"> <button onclick="player2Turn()">Enter</button> <div class="functions"> <button onclick="playAsWhite()">PLAY AS WHITE</button> <button onclick="playAsBlack()">PLAY AS BLACK</button> <button onclick="reset()">RESET</button> </div> He definido el archivo fuente ("main.js") correctamente y el script se carga al final del body .
Su código es correcto Debería ser "onclick". Pero no se accede correctamente a su archivo javascript en html.