1

Im making a zork style game in HTML using javascript.

My game currently looks like this,

<script>

$(document).keypress(function(event) {
        if (event.which == 13) {
         $(".output").append("

Inside the append goes what part of the story you want to print. When the user inputs an answer, A/B/C, then it spits out an answer based on if then.

 $(document).keypress(function(event) {
        if (event.which == 97) {
            $(".output").append("

Problem is it will spit out every single answer I have for that input. I need to find a way for HTML or JS to wait for input then continue on.

4
  • You can try using prompt() Commented Oct 2, 2017 at 23:32
  • 2
    There is no such concept in webpage JS. In the browser, your js is event-driven. That means your code runs in response to events, updates some state and stops running. So to stop and wait, simply quit your function. Save some value in a variable before so next time your function runs you know where to resume from. Commented Oct 2, 2017 at 23:34
  • do you mean ,for example ,if user enter a/b/c then do something , if he enter d/f/f do something else? Commented Oct 2, 2017 at 23:38
  • I think you need to show more than those 6 lines of code. My guess is you need to add logic.... Commented Oct 2, 2017 at 23:39

1 Answer 1

1

use:

$(".temporaryoutput").html(" test ");
$(".temporaryoutput").fadeOut(1000);
$(".output").append("test"); 

append add all your answer to the string. html will show current answer. You can solve the rest with jQuery.Deferred() - https://api.jquery.com/category/deferred-object/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.