It gets score if i click on the red one. If i click on the red ball, even after winning score or losing score it still count. so how to stop counting after specific number?
1
-
Please go through Why not upload images of code/errors when asking a question?– Sudhir OjhaOct 29, 2020 at 10:16
Add a comment
|
3 Answers
I think this may be your solution:
function clickHandler(e) {
var elem= getElementAt(e.getX(), e.getY());
if(score !=0)
{
if(elem != null && elem.getColor() == Color.red)
{
score++;
} else {
score--;
}
}
-
Thank u so much, that was it! 15 in winning point and how to make it so after 15 point, make it so counting stops?– RyeontOct 29, 2020 at 10:43
-
No problem. within the if(score!=0), add && !(score==WIN_SCORE) in this way, reached score=win_score, the if will break Oct 29, 2020 at 10:48
-
OMG Thank u so much! my brain froze and i really couldn't think of a way lol– RyeontOct 29, 2020 at 10:52
-
set a boolean and prior changing use it in the if statement.
if (isPlaying && ...otherConditions) {
your code to change score here
}
< script >
$(function() {
// #max number to win is 10
var score = 0; // set score here
var Win_Score = 10; //max score to win.
//on click event to count score
$("#btn").on('click', function() {
if (score != null && score <= Win_Score - 1 && score > 0) {
// if score is null and less then max socre 10 it will increase score by 1 every click until Win_score 10;
score++;
console.log(score)
}
if (score == 0) {
// if score 0 it will show you loss and stop counting
console.log('Loss')
}
if (score == 10) {
// if score 10 it will show you Win and stop counting
console.log('Win')
}
})
})
<
/script>
-
I set the code according to your code please check and trace it! Oct 29, 2020 at 11:26