HTML5 Lives are not updating

I have a Maze that you go through with your mouse and I have a function for lives which is

var life = 3;
function lives(){
life --;
}

the way I am displaying this lives is

<script type="text/javascript">
    document.write("<div id='hp'>" + "Lives: " + life + "</div>");
</script>

I am calling the function with these blocks but they aren’t updating the lives Help! <img id="a1" src="blackpixel.png" onMouseOver="lives()"/>

Answer

Your onmouseover only update the value of variable lives, but you do not update the display of Lives. You can add this line after line --;:

document.getElementById('hp').innerHTML = 'Lives: ' + life;

Leave a Reply

Your email address will not be published. Required fields are marked *