1
I’m starting to build a program that simulates an ATM with 3 banking options and an option for the user to terminate the process. Only after the operation done by the user, I tried using the multiple decision command switch
case
within the loop of repetition while
to return to the start menu do
, but the method did not work very well:
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 executing the code, the script runs normally in the browser, but only that it always stays in the initial menu, not running the rest of the program.
In this way, which method would be more appropriate to solve this case?
Java doesn’t accept, does that make it a good language? And now Maniero? p
– user28595
Certainly better than JS :) Great advantage... : D Note that the problem is only the lack of
;
why the JS accepts, so it’s not so surprising, we know that the JS works without the;
.– Maniero