0

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);
        }
    })  
});

1 Answers1

0

You are missing a $:

$('#user-input')

Chris
  • 4,255
  • 7
  • 42
  • 83
  • tried this, it worked!!! and now I'm not getting any response whenever I hit enter. From what I THOUGHT, I am supposed to get back the value of whatever is typed in the input box after I hit enter. I know I did something wrong.. I just don't know what. – Stephen Woodbury Apr 05 '20 at 05:04