Thank you for contacting.
I just checked the provided by you code and it worked on a Nexus device. Clicking the button alerted and by clicking 'Yes', the app closed.
In order to help you further, could you please share some more information about, how is this not working on your side. For example, if you try it in the AppBuilder Simulator, are there any console errors, or does the alert even show? If the issue is only reproducing when deployed on actual device, could you tell us, on what device you are trying it?
Thank you for the help in advance. I am looking forward to your reply.