One of the case statements in the top function below is not going in order. Currently, it goes straight to the prompt, and if you click Cancel, operatorPickup
is never heard at all. If I type 'police', I get the police recording which is in a different function called at the end of the current function and then I get OperatorAnswer
which makes absolutely no sense which it is going in the order 2, 3, 1 - when 3 is not even in the same function!
From previous experience, I tried delaying the prompt in case alerts, prompts, or confirms blocked the UI and took precedence, but that didn't help either.
function response() {
switch(number) {
case "0":
var operatorPickup = new Audio('OperatorAnswer.wav');
operatorPickup.play();
setTimeout(function() {
number = prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");
number = number;
operatorPutCallThrough();
}, 9);
break;
case "911":
var pickup911 = new Audio('911-xxx-fleet.mp3');
pickup911.play();
break;
case "18477651008":
var pickupMCI = new Audio('MCI.wav');
pickupMCI.play();
break;
case "8675309":
var pickup8675309 = new Audio('discoornis-bell-f1.mp3');
pickup8675309.play();
break;
case "police":
break;
default:
var pickupDefault = new Audio('ldcircuits-bell-f1.mp3');
pickupDefault.play();
}
}
function operatorPutCallThrough() {
if (number == "police") {
var operatorPoliceTransfer = new Audio('OperatorPolice.wav');
operatorPoliceTransfer.play();
}
response();
}
How can I force case "0" in switch(number)
to execute in order?