이 코드는 기본적으로 사용자에게 무엇을해야하는지 물어 본 다음 2 가지 기능을 사용하여 실제 변수에서 돈을 더하거나 뺍니다. 그러나 변수는 코드에 의해 업데이트되지 않습니다. 이유는 모르겠다.내 "계정 잔액"변수가 코드에 의해 업데이트되지 않았습니다.
actbal = (100);
confirm("Would you like to view account balance? Place a deposit? Or make a withdrawl? Press OK to continue!");
do
{
var v = "VIEW";
var d = "DEP";
var w = "WITH";
var cont1 = prompt('Type: "VIEW" , "DEP" , or "WITH" to do their respective comands');
if(v === cont1.substring(0))
{
confirm("Your account balance is: " + actbal);
}
else if (d === cont1.substring(0))
{
var depo = prompt("How much do you want to deposit?");
var cat = parseFloat(depo);
if(cat < 0)
{
alert("You cant Deposit a negative number...");
}
else
{
confirm("Your new account balance is: " + deposit(cat));
//var actbal = actbal + cat;
}
}
else if (w === cont1.substring(0))
{
var With = prompt("How much do you want to withdrawl?");
var dog = parseFloat(With);
if(dog < 0)
{
alert("You cant Deposit a negative number...");
}
else
{
confirm("Your new account balance is: " + withdrawl(dog));
}
}
else
{
alert("You have not entered a command correctly!");
}
}
while
(
confirm("Do you want to continue with your account?")
);
var deposit = function(cat)
{
actbal = +actbal +cat;
return +actbal +cat;
};
var withdrawl = function (dog)
{
actbal = actbal - dog;
return actbal - dog;
};
왜 'cont1' 대신'cont1.substring (0)'을 사용합니까? – Barmar
디버깅을 할 때 Javascript 콘솔에서 오류를 발견하지 못하셨습니까? – Barmar
부분 문자열 찾기를 제거한 후에 작동합니다. 나는 그것이 그것을 쉽게하기를 기대하지 않았다. 코드를 더 단순화하기 위해이 코드를 변경 하겠지만 코드에는 오류가 없습니다. 내 문제는 다른 포스터에 따르면 (그리고 그 (것)들에 의해 입증 된) 함수 선언이 잘못 배치 된 것이 었습니다. 어쨌든 도움을 주셔서 감사합니다! – ShowmenTv