你好,我試圖讓+ =來增加平衡值。我現在明白,在Java腳本中使用+ =是通過引用傳遞的,但是我怎樣才能使用它來傳遞值。加上等於操作員錯誤
alert("Welcome to the Online Bank Teller");
var balance = 100.00;
var amount;
var run = true;
do{
var pick = prompt("Make a selection...\n1-Check Balance, 2-Deposit, 3-Withdraw, 4-Quit");
if(pick == 1){alert("Your balance is: $" + balance.toFixed(2));}
else if(pick == 2){
amount = prompt("Enter the amount you want to deposit: $");
if(amount > 1000){alert("You can only enter up to $1000 per deposit!");}
Right here--->balance += amount;
alert("Your new balance: $" + balance.toFixed(2));
}
else if(pick == 3){
amount = prompt("Enter the amount you want to withdraw: $");
if(amount > balance){alert("Amount exceeded account balance!");}
else if(amount > 500){alert("The max you can take out is up to $500 per withdraw!");}
else if (amount <= balance){
balance -= amount;
alert("Your new balance: $" + balance.toFixed(2));
}
}
else if(pick == 4){run = false;}
else{alert("Not a valid choice!");}
}while(run)
當用戶輸入新的存款時,我如何獲得它以更改變量內部的值。
我得到
Your balance is: $10022
,而不是
Your balance is: $122
在此先感謝...
Whay是否被標記爲'java'? –