My goal is to have a count start at 100 and then either count up or down by 1 when a specific keyboard button is pressed. Currently, I am using the keys 8 and 2 on the keypad, which represent ascii numbers 104 and 98.
So far, the code I have only allows for counting down, but I am unable to make it count up when key 104 is pressed.
I'm wondering what I am missing in my code to achieve this.
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>