I'm trying to code a text-based adventure game, yes like Zork, and I keep getting the above error message. I tried a few workarounds, but I keep getting the same result. I'm pretty new to this forum, so I hope I can find some good help!!
Here is what I have tried recently:
$(document).ready(function(){
$(document).keypress(function(key){
var isFocused = ('#user-input').is(':focus')
if(key.which === 13 && isFocused) {
var value = $('#user-input').val();
alert(value);
}
})
});
This is what I had originally coded, but I was told to try and add in the variable to fix the issue:
$(document).ready(function(){
$(document).keypress(function(key){
if(key.which === 13 && ('#user-input').is(':focus')) {
var value = $('#user-input').val();
alert(value);
}
})
});