lundi 18 mars 2019

Can't figure out whether this if statement is wrong or the clearInterval

Was playing around with a few tutorials I found online which then I came across to this, not sure how why my if statement won't work

var myVar;
var myNum;
myNum=0;

function alertFunc() {
  myNum=myNum+1;
  console.log("Hello! " + myNum);
}

function myFunction() {

  myVar = setInterval(alertFunc, 1000);

  if (myNum==3){
    clearInterval(myVar);
  }
}


console.log(myFunction());

Aucun commentaire:

Enregistrer un commentaire