I'm completely new to Javascript and for my assignment, I have been tasked with developing a letter guessing game. Although I've completed most of it, I wanted to take things a step further by incorporating an alert when anything other than a letter is pressed. I came across this helpful example just recently...
toLowerCase() != key.toUpperCase()
Yet, the input still includes arrow keys along with the six keys above them. Despite using onkeyup to return a string for these, I am struggling to isolate them using charAt(1). It doesn't seem to be working as intended.
function isLetter(key) {
if (key.toLowerCase() != key.toUpperCase() && key.charAt(1) === '') {
return true;
} else {
return false;
}
}
Additionally, here is the keyup function:
document.onkeyup = function(event) {
keyPress = event.key;
if (!isLetter(keyPress)) {
return alert('Please only enter letters');
}
}