- Mar 26, 2005
- 4,094
- 123
- 106
Reusing this thread to ask another question. Please look at my most recent post
When I try to get a total account balance after the 3 deposits the program concatenates instead of adding and I fail to see why. I already spent 4 hours trying to figure this out myself, and I cannot take it anymore. I need some help, as much as I'd love to be able to do this solo.
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
// declare variables
var firstName;
var lastName;
var fullName;
var openingBalance;
var firstDeposit;
var secondDeposit;
var thirdDeposit;
var totalAccBal_1;
//declare constants
var BR = "<br />";
//user input
firstName = prompt("Please enter your first name.");
lastName = prompt("Please enter your last name.");
fullName = firstName + " " + lastName;
openingBalance = prompt("Enter your opening balance.");
firstDeposit = prompt("Enter your first deposit.");
secondDeposit = prompt("Enter your second deposit.");
thirdDeposit = prompt("Enter your third deposit.");
//perform conversions
parseFloat(openingBalance);
parseFloat(firstDeposit);
parseFloat(secondDeposit);
parseFloat(thirdDeposit);
parseFloat(totalAccBal_1);
//perform calculations
totalAccBal_1 = openingBalance + firstDeposit + secondDeposit + thirdDeposit;
//display all information
document.write("The purpose of this program is to act as a banking simulation" + BR);
document.write("<====================================================================>" + BR);
document.write("Welcome" + " " + " " + fullName + BR)
document.write("Your opening balance is: " + " " + openingBalance + " " + BR);
document.write("Your first deposit is: " + " " + firstDeposit + " ");
document.write("Your second deposit is: " + " " + secondDeposit + " ");
document.write("Your third deposit is: " + " " + thirdDeposit + " " + BR);
document.write("Your account balance after the 3 deposits is: " + totalAccBal_1 + BR);
//end the program
document.write("Good-Bye, " + fullName + "!");
</script>
</body>
</html>
When I try to get a total account balance after the 3 deposits the program concatenates instead of adding and I fail to see why. I already spent 4 hours trying to figure this out myself, and I cannot take it anymore. I need some help, as much as I'd love to be able to do this solo.
Last edited:
