初学者,请帮我看看这个简单JS程序

来源:百度知道 编辑:UC知道 时间:2024/06/12 09:30:06
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>
<script language="javascript">
<!--
function grade(score)
{
this.score=score;
if(score<60)
alert("不及格");
if((score>=60)&&(score<=75))
alert("合格");
if((score>=76)&&(score<=85))
alert("良好");
if(score>=86)
alert("优秀");
}

-->
</script>

<body>

<script language="javascript">
<!--
var name;
var class;
name=prompt("请输入自己的名字","");

class=prompt("请输入自己的班级","");
if(confirm("你的名字是:"+name+" 你的班级:"+class)==true)
{
alert("你的名字是:"+name+" 你的

你有三个错误,尽量避免使用name、class等作为变量,里面函数中的逗号应该使用半角,修改后执行正确的程序如下:

<head>
<metanbsp;http-equiv="Content-Type"nbsp;content="text/html;nbsp;charset=gb2312"nbsp;/>
<title>无标题文档</title>

</head>
<scriptnbsp;language="javascript">nbsp;<!--
functionnbsp;grade(score)
{
nbsp;this.score=score;
nbsp;if(score<60)
nbsp;alert("不及格");
nbsp;if((score>=60)&&(score<=75))
nbsp;alert("合格");
nbsp;if((score>=76)&&(score<=85))
nbsp;alert("良好");
nbsp;if(score>=86)
nbsp;alert("优秀");
}
--></script>

<body>

<scriptnbsp;language="javascript"><!--
varnbsp;nam;
varnbsp;clas;
nam=prompt("请输入自己的名字","");
clas=prompt("请输入自己的班级","");
if(confirm("你的名字是:"+nam+"nbsp;你的班级: