Because your code is "listening" for up/down keys, the focus on your webpage might not be on document.addEventListener which is why nothing happens.
On the stackoverflow page it's discussing how and where to listen for certain keys, therefore, you may need to change your javascript to do the...