I've been trying to run a function that adds an amount to a variable and then shows that new value using text but I can't seem to get it to work properly.
I made a element and then used the style attribute to make it a yellow square and after that I added a element to use javascript to document so that when you click on the it shows you увеличение одного. Вот код из страницы.
Код: Выделить всё
let numberClicked = 0;
const clicked = () => {
numberClicked = numberClicked+1;
};
document.getElementById("id").onclick = clicked;
document.write(numberClicked);
Когда я запустил код, и текст из document.write () появился, но щелчок не отвечал. Я попытался добавить скобки после щелчка в 8 -й строке, но это просто вызывает функцию один раз, а затем ничего не происходит. Я не могу найти ничего, что можно сделать, где бы я ни искал. Я также использую страницы GitHub, чтобы сделать это, если это влияет на это.
Подробнее здесь:
https://stackoverflow.com/questions/796 ... d-then-sho