Tuesday 20 August 2013

Javascript reading and changing variables

Javascript reading and changing variables

Ok, I've been up all night try to get this working and i'm a complete
javascript newbie
var Hunger=8;
var interval = setInterval( increment, 10000);
function changeImage(a) {
document.getElementById("img").src=a;
window.setTimeout(goIdle,20000)
}
function goIdle() {
document.getElementById("img").src="idle.gif";
function increment(){
Hunger = Hunger % 24 + 1;
if (Hunger >= 24)
}
if (Hunger >= 12)
changeImage("cry.gif")
}
}
function eat() {
if (Hunger == 6) {
changeImage("love.gif");
var Hunger=0
}
else {
...
}
}
What happens is that when I press the button to trigger it,
<input type="button" value="Eat" onclick='eat();' />
It changes the image but the hunger doesn't go down

No comments:

Post a Comment