Code not working sequentially

I want to run a code sequentially in the order it is written but using console I am seeing that the code below is being run midway (while the timer is still running). I want it to run after the timer closes (preferably 1 second later timer reaches 0). I have tried async and await but not getting the required results.

export function button1_click(event) {
 
    number = number + 1;
    $w('#list').setCurrentItemIndex(number);
    $w("#names").setFieldValues( {
 "status":  "Running",
 "number":  number
    } );
 let seconds = 12;
 let countdown = setInterval(function () {
 if (seconds >= 0) {
    $w('#admintimertext').text = seconds + " seconds left"
    seconds = seconds - 1
  } else {
    clearInterval(countdown)
  }
},1000);

$w("#names").setFieldValues( {
 "status":  "Pause"
    }
)
}

Please help. Not able to figure out where I went wrong.

I’m not really sure I got what you were trying to do, but if want to set the field value to status:pause once the countdown hits the minus one, then:

//......
const countdown = setInterval(runTimer, 1000);
function runTimer() {
 if (seconds >= 0) {
    $w('#admintimertext').text = seconds + " seconds left";
  seconds--;
  } else {
      clearInterval(countdown);
	$w("#names").setFieldValues( {
 		"status":  "Pause"
  	  });
  }
};
//....

The console log afterwards is not showing the status as pause. What I am trying to do is I have a code on another page which changes based on the status value. So after the timer runs it should go to pause and on another page I have setInterval for each second.

You can also suggest a different way if you think it can be efficient.

Thanks.

Adding the save code fixed that. I think the dataset needs to be saved each time.