且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JAVASCRIPT作业,我无法运行它,有人可以帮我修复代码吗?

更新时间:2023-12-05 14:30:16

您的代码存在一些问题。

1.你不能使用Function来声明一个函数,因为它不是JS中的关键字。

你可以使用函数(记住JS区分大小写)。

2.您无法使用数字启动变量/参数名称。详细了解有效的JS

标识符名称此处 [ ^ ]。

3.从参数名中删除1后,你会发现JS解析器

找不到变量Name。如前所述,JS区分大小写,这意味着JS和Name是两个不同的东西。功能名称相同,带有帐户的声明,但使用帐户。



纠正这些问题后,您会发现代码运行。

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.
<!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>