Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<html>
<head>
<script type="text/javascript">

// Program name: AccountClass.html
// Purpose: Use a constructer function
// to create an object
// Author: Arbr Krasniqi
// Date last modified: April-25th-2018

// Constructor function for the Account Class
Function account(type, num, 1name, fName, bal) {

this.acctType = type;
this.acctNumber = num;
this.lastName = 1Name;
this.firstName = fName;
this.acctBal = bal;
} // end Account function
</script>
</head>

<body>
<script type="text/javascript">

// Variables and Constants
var BR = "<br/>";   // HTML line break tag 

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

// Create an Account object 
var mySavingsAcct = new Account("S", 1376433,
"Dunes", "Sandi", 80.00);

//Thank the user and end the program
document.write("Thank you!" + BR);
</script>
</body>
</html>


What I have tried:

Opening the file as a html from texteditor on mac.
Posted
Updated 6-May-18 20:16pm
v2

1 solution

There are a few issues with your code.
1. You cannot declare a function using "Function" because it is not a keyword in JS.
You can use function (remember JS is case sensitive).
2. You cannot start a variable/parameter name with a number. Read more about valid JS
identifier names here[^].
3. After you have removed the 1 from the parameter name you'll find out that JS parser
cannot find the variable Name. As pointed out earlier JS is case sensitive, that means name and Name are two different things for JS. Same problem with the function name, a declaration with "account" but usage with "Account".

After you correct these issues you'll find that your code runs.
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

// Program name: AccountClass.html
// Purpose: Use a constructer function
// to create an object
// Author: Arbr Krasniqi
// Date last modified: April-25th-2018

// Constructor function for the Account Class
function Account(type, num, name, fName, bal) {

this.acctType = type;
this.acctNumber = num;
this.lastName = name;
this.firstName = fName;
this.acctBal = bal;
}; // end Account function
</script>
</head>
<body>

<script>

// Variables and Constants
var BR = "<br/>";   // HTML line break tag 

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

// Create an Account object 
var mySavingsAcct = new Account("S", 1376433,"Dunes", "Sandi", 80.00);

//Thank the user and end the program
document.write("Thank you!" + BR);
</script>

</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900