skip to Main Content
$(document).keydown(function () {
if (!started)
    nextSequence();
})

$(document).keypress(function() {
  if (!started) {
    $("#level-title").text("Level " + level);
    nextSequence();
    started = true;
  }
});

For press down, change the title:
The h1 title starts out saying "Press A Key to Start", when the game has started, change this to say "Level 0".

2

Answers


  1. Your question is a little confusing. The exclamation point (!) means "not" (in this case { if "not" started } i.e. if started == false). but I’m not sure what you are asking in regards to running the "Function 1 time at a time." A word of warning, people here will really jump down your throat if you ask questions that could possibly be answered elsewhere on the internet so it might be worth running at least a few Google searches before you post. If you could reword the first part of your question to be a little more clear you might get some answers, but I would advise editing out the part asking about the (!) symbol.

    I hope you have a pleasant day!

    Login or Signup to reply.
  2. add if (e.repeat) return; to the beginning of the function.

    $(document).keydown(function(e) {
        if (e.repeat) return;
        //3. The h1 title starts out saying "Press A Key to Start", ...
        $("#level-title").text("Level " + level);
        nextSequence();
        started = true;
    });
    

    The exclamation mark (“!”) symbol, called a “bang,” is the logical “not” operator.

    If the started var is initialized to false before the keypress then (!started) will evaluate to true and the code in that block will run. When the key is pressed and the code is run, started will be set to true, therefore if additional keypresses happen (!started) will evaluate to false and the code will not be run again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search