im new to this and i have this simple code for my game that increases score on click
var count = document.getElementById("score");
var score = 0;
var audio = new Audio('pop.mp3');
function increaseScore(){
score ;
count.innerHTML = score;
}
how do i add events like if score is bigger than 100 do a certain thing i already tried
if (score > 100) {
}
and its not workin
CodePudding user response:
After the score increase, then do conditional things..
function increaseScore() {
score ;
count.innerHTML = score;
if (score > 100) {
// do something
}
}
CodePudding user response:
You would not need an eventListener for this, because let's say if you had a button and each time the button is clicked, then you would increase a score by one, in this case you could use eventListener. In your case, just use conditional statements like
if(score == 100) {
//do something here
}
or you can use conditional ternary operator if you have two options of what you want to happen in a certain scenario:
score > 100 ? doSomething : OR doSomethingOtherwise.