I am starting to put together a program that simulates an ATM with 3 banking options and an option for the user to terminate the process. But after the user-made operation, I tried to use the multiple decision command switch
case
within the loop while
to return to the do
start menu, but the method did not work:
var opcao, vl_saq;
var saldo = 0;
var min = 0;
var max = 2000;
do {
opcao = parseInt(prompt("Escolha uma opção:\n1 - Saque\n2 - Depósito\n3 - Saldo\n0 - Sair")); // MENU inicial
}
while (opcao != 0){
switch (opcao) {
case 1:
vl_saq = parseInt(prompt("Digite o valor do saque:"));
if (vl_saq > saldo) {
if (vl_saq > 0 && vl_saq < max) {
alert("O saque está sendo realizado...\nAperte em OK");
saldo -= vl_saq;
alert("Operação Realizada!");
}
else {
alert("Só podem entrar no saque, valores que sejam entre R$0,00 e R$2.000,00");
}
}
else{
alert("Saldo insuficiente! Você pode sacar\nR$ "+saldo.toFixed(2));
}
break;
}
}
When running the code, script runs normally in the browser, but only that it always remains in the start menu, not running the rest of the program.
In this way, which method would be most appropriate to solve this case?