嗨,我是一名初级程序员,我刚开始学习 javascript。我正在尝试构建一个简单的 javascript 程序,该程序将提示用户从候选人列表中选择一个名称,然后选择他们想要接收信息的类别。然后程序应该显示该信息。我编写了下面列出的代码,但由于某种原因它不起作用,我无法弄清楚。任何帮助,将不胜感激。谢谢
<html>
<head>
<title>interndatabase</title>
<script type="text/javascript">
//<!CDATA[
//stores data about the applicants
applicantName= new array ("Joe","Sarah", "Roger", "Mike");
applicantCategory= new array ("University","Year","SAT","GPA");
applicantInfo= new array (
new array ("Stanford","Senior","2250","3.6"),
new array ("UC Berkeley","Junior","2100","3.9"),
new array ("MIT","Junior","2200","3.3"),
new array ("Carnegie Mellon","Sophomore","2150","3.4")
);
//this function should evaluate said data
function getInfo (){
var theApplicant=" ";
var menuA="Please choose an applicant by typing a number\n";
menuA+="0)Joe\n";
menuA+="1)Sarah\n";
menuA+="2)Roger\n";
menuA+="3)Mike\n";
theApplicant=prompt(menuA);
return theApplicant;
var theCategory=" ";
var menuB="Please Choose a category by typing a number\n";
menuB+="0)University\n";
menuB+="1)Year\n";
menuB+="2)SAT\n";
menuB+="3)GPA\n";
theCategory=prompt(menuB);
return theCategory;
}//end function
//main code evaluates the result, and returns the correct info to the user
function main () {
var output=" ";
var name=getInfo()
var category=getInfo()
var result=applicantInfo [name] [category];
output="The database belonging to" +applicantName;
output+="registers" +result+ "in that category.";
alert(output);
}//end main
</script>
</head>
<body>
</body>
</html>