How do i get a if statement to stop running after it has already run once?

I’m trying to make a counter on my wix website that shows 3 numbers counting up.

The first counts up to 48 the second to 100 and the third to 16.

My problem is that after it has run once when i leave the view finder then go back to the view finder it just keeps running again from the beginning.

How do I get the code to stop running for good when it has already run once and then it only runs again when the person either refreshes the page or leaves and comes back.

The code I used was this.

export function text113_viewportEnter1(event) {
let startNum1 = 0;
let endNum1 = 48;
let startNum2 = 0;
let endNum2 = 100;
let startNum3 = 0;
let endNum3 = 16;
const duration =  50; // 50 milliseconds

$w.onReady(function () {
    setInterval(()=> {
        countUp();  
    }, duration);
});

function countUp(){ 
 if (startNum1 <= endNum1 ){   
        $w('#text112').text =  startNum1.toLocaleString().toString();
        startNum1++;
    }
 if (startNum2 <= endNum2 ){   
        $w('#text113').text =  startNum2.toLocaleString().toString();
        startNum2++;
    }
 if (startNum3 <= endNum3 ){   
        $w('#text114').text =  startNum3.toLocaleString().toString();
        startNum3++;
    }
}
}

Your counters got reset to 0 every time you re-enter the view:

let startNum1 =0 ;
let endNum1 =48 ;
let startNum2 =0 ;
let endNum2 =100 ;
let startNum3 =0
; let endNum3 =16 ;
const duration = 50 ; // 50 milliseconds

export function text113_viewportEnter1 ( event ) {
$w . onReady ( function () {
setInterval (() => {
countUp ();
}, duration );
});

Yeah but my question is, how do I get it to stop doing that and just stay at 48, 100, and 16 when their done running.

function countUp (){
if ( startNum1 < endNum1 ){
$w ( ‘#text112’ ). text = startNum1 . toLocaleString (). toString ();
startNum1++ ;
}
if ( startNum2 < endNum2 ){
$w ( ‘#text113’ ). text = startNum2 . toLocaleString (). toString ();
startNum2++ ;
}
if ( startNum3 < endNum3 ){
$w ( ‘#text114’ ). text = startNum3 . toLocaleString (). toString ();
startNum3++ ;
}
}

I got the answer it works perfectly

let flag = true;

export function text113_viewportEnter1(event) {
 let startNum1 = 0;
 let endNum1 = 48;
 let startNum2 = 0;
 let endNum2 = 100;
 let startNum3 = 0;
 let endNum3 = 16;
 const duration = 50; // 50 milliseconds

  $w.onReady(function () {
 if (flag) {
      setInterval(() => {
        countUp();
      }, duration);
    }
  });

 function countUp() {
    flag = false;

 if (startNum1 <= endNum1) {
      $w("#text112").text = startNum1.toLocaleString().toString();
      startNum1++;
    }
 if (startNum2 <= endNum2) {
      $w("#text113").text = startNum2.toLocaleString().toString();
      startNum2++;
    }
 if (startNum3 <= endNum3) {
      $w("#text114").text = startNum3.toLocaleString().toString();
      startNum3++;
    }
  }
}