const spamCheckButton = document.getElementById('send-comment');
const comment = document.getElementById('comment');
const spamWord = document.getElementById('spam-word');
let counter = 0;
const isSpam = function (string, word, timesWord) {
if(string.includes(`${word}`)){
counter++;
return false
}
if (counter > timesWord||counter === timesWord){
return true
}
};
spamCheckButton.addEventListener('click', isSpam(comment.value , spamWord.value, 3 ))
window.addEventListener("load", function() {
const spamCheckButton = document.getElementById('send-comment');
spamCheckButton.addEventListener('click', function(e) {
isSpam(comment.value, spamWord.value, 3);
});
});
Вы в евент добавляете не функцию, а результат ее выполнения. Правильный вариант
spamCheckButton.addEventListener('click', ()=>isSpam(comment.value , spamWord.value, 3))
либо так
spamCheckButton.onclick = () =>isSpam(comment.value , spamWord.value, 3)
Сборка персонального компьютера от Artline: умный выбор для современных пользователей