$(document).keypress(function() {
if (!started) {
$("#level-title").text("Level " + level);
nextSequence();
started = true;
}
});
I don't understand what does (!started)
do inside the if condition.
$(document).keypress(function() {
if (!started) {
$("#level-title").text("Level " + level);
nextSequence();
started = true;
}
});
I don't understand what does (!started)
do inside the if condition.
Assuming started
is a Boolean variable (contains true
or false
) that represents the state of something that could be started or stopped, then the Statement,
if (!started) {
is asking IF NOT STARTED THEN... ELSE...
!
represents the Not Operator and started
represents the variable. This is a logical condition where started
can be true
or false
. If started
is true
, then !started
is false
. If started
is false
then !started
is true
.
Here is another way the Not Operator can be used.
var started = true;
started = !started;
console.log(started); // false