Home > database >  How Can I run the Function 1 time at a time using Kedown? also what does this symbole means? "!
How Can I run the Function 1 time at a time using Kedown? also what does this symbole means? "!

Time:01-03

$(document).keydown(function () { if (!started) nextSequence();

})

$(document).keypress(function() { if (!started) {

//3. The h1 title starts out saying "Press A Key to Start", when the game has started, change this to say "Level 0".
$("#level-title").text("Level "   level);
nextSequence();
started = true;

} });

CodePudding user response:

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!

CodePudding user response:

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.

  • Related