View Single Post
Old 01-30-2013, 10:46 PM   PM User | #1
Modify_inc
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Modify_inc is an unknown quantity at this point
Last document.write not displaying text statement

The last statement in my example code from my school book, document.write("Thank you!" + BR); is not displaying and I'm not certain why. I'm taking a course and I am using the book's sample code to practice.

I have narrowed it down to the html tags nested within the script (in the middle, not at the beginning). Although I feel the root of the problem lies with the "creating of the account object" that falls right before the, "Thank you!" statement.

Using the sandbox from danml.com, I was able to remove or comment the aforementioned html tags and the script appeared to execute in its entirety, displaying "Thank you!"

I'm certain though, that this snippet of code is needed in some form or fashion to properly execute the remaining code.

If I leave it missing, I get an error that my account deposit function is not a function.

If I put the html tags back, it stops after displaying the program's purpose and refuses to display the "Thank you!" statement.

I'm just a student, so be gentle. Here is the example code from the book:

Code:
<html>
<head>
<script type="text/javascript">

// Program name: AccountClass.html
// Purpose: Use a constructor function
// to create an object
// Author: Paul Addison
// Date last modified: 01-Sep-2011
// Constructor function for the Account class
function Account(type, num, lName, fName, bal)  {
this.acctType = type;
this.acctNumber = num;
this.lastName = lName;
this.firstName = fName;
this.acctBal  = bal;

// Link the current object to the class methods
this.deposit = deposit;
this.withdraw = withdraw;
this.changeName = changeName;
this.inquire = inquire;
this.displayInfo = displayInfo
} 		// end Account function

// Function to deposit in the account
function deposit(amt)	{
	this.acctBal = this.acctBal + amt
	document.write("New balance: $" + this.acctBal + BR);
}
// Function to withdraw from account
function withdraw(amt)	{
	this.acctBal = this.acctBal - amt;
	document.write("New balance: $" + this.acctBal + BR);
}
// Function to change the first and last name
function changeName(lName, fName)	{
	this.lastName = lName;
	this.firstName = fName;
	document.write("The name has been changed to " + this.fName + " " + this.lName + BR);
}
// Fucntion that returns the current balance
function inquire()	{
	document.write("Balance: $" + this.acctBal + BR);
}
// Function that displays all account information
function displayInfo(amt)	{
	document.write("Account type: " + this.acctType + BR);
	document.write("Account #: " + this.acctNumber + BR);
	document.write("Last name: " + this.lName + BR);
	document.write("First name: " + this.fName + BR);
	document.write("Balance: $" + this.acctBal + BR);
}
</script>
</head>
<body>
<script type="text/javascript">

// Variables and constants
var BR = "<br />";

// State program purpose
document.write("Account program." + BR);
document.write("This program creates an account." + BR);

var mySavingsAcct = new Account("S", 1376433, "Dunes", "Sandi", 80.00);

// Deposit $100
mySavingsAcct.depost(100.00);

//Withdraw $50
mySavingsAcct.withdraw(50.00);

// Inquire about balance
mySavingsAcct.inquire();

// Display info for verification
mySavingsAcct.displayInfo();

// Thank the user
document.write("Thank you!!" + BR);
</script>
</body>
</html>
Modify_inc is offline   Reply With Quote