$(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
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!
add
if (e.repeat) return;
to the beginning of the function.The exclamation mark (“!”) symbol, called a “bang,” is the logical “not” operator.
If the
started
var is initialized tofalse
before the keypress then(!started)
will evaluate totrue
and the code in that block will run. When the key is pressed and the code is run,started
will be set totrue
, therefore if additional keypresses happen(!started)
will evaluate tofalse
and the code will not be run again.