I made a prototype function, game.chooseSymbol(symbol), and I want it to activate with a click event. when I use document.querySelector(’.something’).addEventListener(‘click’, game.chooseSymbol(symbol), I get an error in the console saying that this is not a function. In stackoverflow I found that you are supposed to add .bind to your function to make this work, but I tried adding .bind to game.chooseSymbol and got an error that it wasn’t a function, not sure if I was using it correctly though. I would appreciate any help with this. Here are links to my code : https://pastebin.com/KpCR6DVg https://codepen.io/icewizard/pen/XEMmGZ
'use strict'
function game (player) {
this.player = null;
this.computer = null;
this.playerMoves = [];
this.computerMoves = [];
this.squares = document.querySelector(this.id);
this.winningCombos = [
[1, 2, 3],[4, 5, 6],[7, 8, 9],
[1, 4, 7],[2, 5, 8],[3, 6, 9],
[1, 5, 9],[3, 5, 7]
];
}
game.prototype.chooseSymbol = (symbol) => {
player = symbol;
//choose computers symbol
player = 'x' ? computer = 'o' : computer = 'x';
console.log(player + computer);
}
document.querySelector('#playx').addEventListener('click', game.chooseSymbol('x'));
document.querySelector('#playo').addEventListener('click', game.chooseSymbol('o'));