I have two functions at the top of my code. Below in a while (i<1) loop, I call one of the functions above. This works the first time, but the second time the function is called it displays an error:
TypeError: undefined is not a function
Below is the code:
var i = 0;
var newBalance = 0;
var deposit = function(amountIn)
{
newBalance = (newBalance + amountIn).toFixed(2);
};
var withdrawl = function(amountOut)
{
newBalance = (newBalance - amountOut).toFixed(2);
};
var choice = prompt("Would you like to access your account?").toLowerCase();
if (choice === "yes"){
while (i<1){
var inOrOut = prompt("Are you making a deposit or a withdrawl?").toLowerCase();
var strAmount = prompt("How much money are you trasfering?");
var amount = parseFloat(strAmount);
if (inOrOut === "deposit")
{
deposit(amount);
}
else if (inOrOut === "withdrawl")
{
withdrawl(amount);
}
else
{
console.log("You did not enter a valid number");
}
console.log("Your new balance is $" + newBalance);
var choiceTwo = prompt("Would you like to make another transaction?").toLowerCase();
if (choiceTwo === "no")
{
i = i + 1;
}
}
}