2

Is it possible to have a invertal function that stop and starts if a variable is too high or too low

How can I make moneymaker stop when it reach 300?

I Tried with this code, but didn't get any results...

Code ex.

var money = 0;
var maxmoney = 300;

var moneymaker = window.setInterval(function(){

    money = money + 1;
    document.getElementById('money').innerHTML = money;
    }, 1000);

function stopInter(){
    if(hp >= maxhp)
    clearInterval(regen);
    }else{
    setTimeout(function(){}, 1000); 
    }
}
NaserIT
  • 41
  • 1
  • 3

1 Answers1

0
var money = 0;
var maxmoney = 300;

var moneymaker = window.setInterval(function(){
    if(maxmoney>money){
        money = money + 1;
      console.log(money);
    }
    document.getElementById('money').innerHTML = money;
    }, 1000);

https://jsfiddle.net/4L2s5e0y/2/

Jows
  • 877
  • 2
  • 11
  • 21