JAVASCRIPT作业,我无法运行它,有人可以帮我修复代码吗? [英] JAVASCRIPT homework, I cant run it, can someone help me fix the code?

查看:69
本文介绍了JAVASCRIPT作业,我无法运行它,有人可以帮我修复代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





我尝试过:



在mac上从texteditor打开文件作为html。



What I have tried:

Opening the file as a html from texteditor on mac.

推荐答案

您的代码存在一些问题。

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>


这篇关于JAVASCRIPT作业,我无法运行它,有人可以帮我修复代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆