now i want to make a web program that when i press keyboard , i change the value of global variable to 1 , if not it is set to 0 . But somehow i cannot change with addEventlistener This is my code:
<script>
var count;
function down(e) {
console.log("down");
count = 1 ;
// body...
}
function up(e) {
console.log("up");
count = 0;
}
window.addEventListener("keydown", down);
window.addEventListener("keyup", up);
document.getElementById('demo').innerHTML = count;
//somehow the output is always undefined instead of 1 or 0 , even though the
//function is executed
</script>
</body>
</html>