Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to confirm if the innerText is equal to something?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>`;
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading