ATM- Javascript help! Hello, wondering if someone can help me out. I am doing an
ID: 3573498 • Letter: A
Question
ATM- Javascript help! Hello, wondering if someone can help me out. I am doing an ATM project web application, that allows the user to manage transaction data. However, i need this program to be more proficient in a way that really looks like a "Real ATM" for example i want to set if the password i set up which is "1234" is wrong more than 3 times, Account gets locked. just like in "Real ATM" also want to ADD at the beginning from which ACCOUNT you want to "deposit " or "withdraw" money. Bascially adding a SAVING and CHECKING account. and if it can be possible explain the code in pseudocode guideline to understan line by line what the code does..thanks
---------------------------------------MY CODE-----------------------------------------------
<html>
<head>
<script>
function verify()
{
var pin = prompt("Enter your ATM PIN");
if(pin != "1234")
{
alert("Invalid pin. Please try again!");
verify();
}
alert("Authenticated!");
document.getElementById("bal").innerHTML = "100";
}
function deposit()
{
var amount = prompt("How much would you like to deposit?");
if(amount <= 0)
alert("Invalid amount. Please try again!");
else
{
alert("Transaction successful. ");
document.getElementById("msg").innerHTML = "$" + amount + " successfully deposited to your account."
document.getElementById("bal").innerHTML = parseInt(document.getElementById("bal").innerHTML) + parseInt(amount);
}
}
function withdraw()
{
var amount = prompt("How much would you like to withdrawal?");
if(amount <= 0)
alert("Invalid amount. Please try again!");
else
{
alert("Transaction successful. Please take your money now.");
document.getElementById("msg").innerHTML = "$" + amount + " successfully withdrawn from your account.";
document.getElementById("bal").innerHTML = parseInt(document.getElementById("bal").innerHTML) - parseInt(amount);
}
}
function exit()
{
var amount = prompt("Would like to make another transaction.Click Cancel to Exit.");
if (amount) {
window.close();
} else {
prompt("Have a nice day!");
}
}
</script>
<body>
Message: <span id='msg'></span><br>
Your Current Balance $: <span id='bal'></span><br>
<input type="button" value="Deposit" />  
<input type="button" value="Withdraw" />
<input type="button" value="EXIT" />
</body>
</html>
Explanation / Answer
<html>
<head>
<script>
function verify()
{
var i=0;
var pin = '';
while(pin != "1234" && i!=3)
{
pin = prompt("Enter your ATM PIN");
if(pin == "1234")
{
alert("Authenticated!");
document.getElementById("bal").innerHTML = "100";
break;
}
else
{
alert("Invalid pin. Please try again!");
i++;
}
}
if(i==3)
alert("Retry Attemptes Over . your Account is locked");
}
function deposit()
{
var amount = prompt("How much would you like to deposit?");
if(amount <= 0)
alert("Invalid amount. Please try again!");
else
{
alert("Transaction successful. ");
document.getElementById("msg").innerHTML = "$" + amount + " successfully deposited to your account."
document.getElementById("bal").innerHTML = parseInt(document.getElementById("bal").innerHTML) + parseInt(amount);
}
}
function withdraw()
{
var amount = prompt("How much would you like to withdrawal?");
if(amount <= 0)
alert("Invalid amount. Please try again!");
else if(amount >= parseInt(document.getElementById("bal").innerHTML))
alert("sorry insufficient balance");
else
{
alert("Transaction successful. Please take your money now.");
document.getElementById("msg").innerHTML = "$" + amount + " successfully withdrawn from your account.";
document.getElementById("bal").innerHTML = parseInt(document.getElementById("bal").innerHTML) - parseInt(amount);
}
}
function exit()
{
var result = confirm("Would you like to make another transaction?");
if (result==false) {
alert("Have a nice day!");
}
}
</script>
<body>
Message: <span id='msg'></span><br>
Your Current Balance $: <span id='bal'></span><br>
<input type="button" value="Deposit" />  
<input type="button" value="Withdraw" />
<input type="button" value="EXIT" />
</body>
</html>
in this web application three buttons are shown for deposit, withdraw and exit
when user first visits this page the page ask for the atm pin it gives three chances to enter correct pin
if not then it locks the account
if success it sets the initial balance to 100
and user have options for deposit withdraw and exit
if user chooses the deposit option
it asks for the amount to deposit and then adds that balance to the initial balance
if user chooses withdraw option
it asks for the amount
if the amount is available in the balanace it withdraws money
else gives error message
if we choose exit
it ask for confirmation
if confirmed it exits
else continues
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.