...

View Full Version : Subtracting won't work



Pregamour
12-25-2011, 10:21 AM
<html>
<script type="text/javascript">
var x=200;
function update()
{
document.getElementById('health').innerHTML=x;
}
function attack()
{
x=x-10;
}
if (x<10)
{
document.write("You Won")
}
</script>
<body onload="update()">
<div id="health">
</div>
<input type="button" value="Attack" onclick="attack()" />
</body>
</html>

I don't see that x loses 10 what's the problem.:confused::confused:

Apothem
12-25-2011, 10:42 AM
When you click on the Attack button, attack is called. x is subtracted by 10, but the innerHTML has not been updated, nor have you checked if x is less tan 10.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum