I am trying to code a tic tac toe game on repl.it. I am trying to code the if (space owned) then part, but I need to find out if a p element includes certain characters to determine if the space is owned. But when I do that, it says in the console, TypeError: document.getElementById(...).includes is not a function
at tac (/code.js:4:35)
at HTMLButtonElement.onclick (/:27:27)
What code should I use to fix that?
The code I am using is:
function tac() {
var tac = prompt('Type the first letter of each word (e.g. If you want the top left, type tl)');
var playerName = prompt('Are you player 1 or 2?');
if (document.getElementById(tac).includes(' is availible')) {
document.getElementById(tac).innerHTML = 'This space is owned by ' + playerName;
} else {
alert('That space is already taken!');
}
}
document.getElementById(...)returns does not implement anincludesfunction. In other word - it's not a string..includes()on the.textContentof the element (a string), not on the element itself.document.getElementById(...).textContent.includes();And does the.includes()function return a boolean? Liketrueorfalse?