-2

i downloaded a java billiard game. I want to modify it.

Note: the sum of the score is store in score_text_total

So when the player shoots the Ball with sum of less than 10, a picture, for example, of a DOG will show

If sum of ball shoots is more than 10 but less 20, picture of CAT (replaces/hides the DOG picture)

If sum of ball shoots is more than 30, a picture of trophy appears (replaces/hides the CAT picture)

<!doctype html>
<html lang="en">
<head>

</style>
</head>


<body>

<img src="assets/images/DOG.gif" style="display: none; background: #000;" id="DOG"/>
<img src="assets/images/CAT.gif" style="display: none; background: #ff0000;" id="CAT"/>

<script type="text/javascript">


var DOG =    document.getElementById('DOG');
var CAT =    document.getElementById('CAT');



function picture() {
if(curent_score < 10) {
DOG.style.display = 'block';
CAT.style.display = 'none';
}
else {
DOG.style.display = 'none';
CAT.style.display = 'block';
}
}


</script>

</body>
</html>
  • 1
    Welcome to [Stack Overflow](http://stackoverflow.com/) ! Please read [How to Ask Question](http://stackoverflow.com/help/how-to-ask) and provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) ! – Saurabh Bhandari Jun 09 '17 at 05:51
  • [Change image based on dropdown using javascript](https://stackoverflow.com/questions/22254608) – Ari Seyhun Jun 09 '17 at 05:54
  • Using a dropdown list will not achieve the desired result. I think statement if else will. but I dont know how. Thanks – Mars Cheruben Garces Jun 09 '17 at 06:48

1 Answers1

0

I'm assuming you mean JavaScript and not Java. I'm also assuming you are using vanilla JS.

You could make a div and then set its background image. This would allow you to style the div/absolutely position it where you want, and then change the picture as a single CSS property.

You could try something like (untested): var score = document.getElementbyId('scoreboard'); score.style.background = "none";

There are similar solutions around on Stack Overflow as well that inspired this suggestion: Set CSS property in Javascript?