I would like to try and confirm the winner of the game. To do this I was planning on using document.getElementById('player1').innerText === 0 to check if player 1 score was equal to zero, but I think the syntax is wrong above. How would I check if the innerText is equal to zero?
function checkWinner() {
if (document.getElementById('player1').innerText === 0) {
message.innerHTML = `<p>${players[1]} you have won the game</p>`;
}
if (document.getElementById('player2').innerText === 0) {
message.innerHTML = `<p>${players[0]} you have won the game</p>`;
}
}
>Solution :
As other have said, innerHTMLL will be a String, but you may convert it to numeric by adding a + sign
if (+document.getElementById('player1').innerText === 0) {
message.innerHTML = `<p>${players[1]} you have won the game</p>`;
}