Like this
Check, then do it.
The code isn’t actually functional, it’s more the concept that matters.