I am trying to get a count from 100 to count up/down by 1 when a keyboard button is pressed. I am currently using the keys 8 and 2 on the keypad which correspond to 104 and 98 ascii numbers.
At the moment the code I am using counts down but I cannot get it to count up on 104 key press.
What am I missing.
var keyY = 100;
document.addEventListener('keydown', function(event){
var keyPressed = event.keyCode;
switch(keyPressed){
case 104:
keyY = keyY + 1;
case 98:
keyY = keyY - 1;
}
console.log('key pressed: ' + keyPressed);
console.log('keyX = ' + keyY);
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
switchstatement carefully: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…