linux EOF

<html>
<head>
<title>Wrox Online Trivia Quiz</title>
<script language="JavaScript" type="text/javascript">
//(1)变量的名字不一致导致了页面显示不出来,所以流程要清楚,变量出现在了什么地方要有数
//(2)如何将其题目内容显示在页面上?如何将javascript语言和页面语言混合起来用?
//
var questionNumber;
function answerCorrect(questionNumber,answer)
{
    var correct = false;
    if(answer == answers[questionNumber])
    {
        correct = true;
    }
    return correct;
}
function getQuestion()
{
   questionNumber = Math.floor(Math.random() * (questions.length));
   var questionHTML = "<p>" + questions[questionNumber][0] + "</p>";
   var questionLength = questions[questionNumber].length;
   var questionChoice;
   for (questionChoice = 1;questionChoice < questionLength;questionChoice++)
   {
      questionHTML = questionHTML + "<input type=radio name=radQuestionChoice"
      if (questionChoice == 1)
      {
         questionHTML = questionHTML + " checked";
      }
      questionHTML = questionHTML + ">";
      questionHTML = questionHTML + questions[questionNumber][questionChoice];
      questionHTML = questionHTML + "<br>";
   }
   document.QuestionForm.txtQNumber.value = questionNumber + 1;
   return questionHTML;
}
function buttonCheckQ_onclick()
{
    var answer = 0;
    while(document.QuestionForm.radQuestionChoice[answer].checked != true)
    {
        answer++;
    }
    answer = String.fromCharCode(65 + answer);
    if(answerCorrect(questionNumber,answer) == true)
    {
        alert("You got it right");
    }
    else
    {
        alert("You got it wrong");
    }
    window.location.reload();
}
var questions = new Array();
var answers = new Array();
questions[0] = new Array();
questions[0][0] = "The Beatles were";
questions[0][1] = "A sixties rock group from Liverpool";
questions[0][2] = "Four musically  gifted  insects";
questions[0][3] = "German cars";

// fourth choice
questions[0][4] = "I don't know. Can I have the questions on Baseball please?";

// assign answer for question 1
answers[0] = "A";
questions[1] = new Array();
questions[1][0] = "Homer Simpson's favorite food is";
questions[1][1] = "Fresh salad";
questions[1][2] = "Doughnuts";
questions[1][3] = "Bread and water";
questions[1][4] = "Apples";
answers[1] = "B";

questions[2] = new Array();
questions[2][0] = "Lisa Simpson plays which musical instrument?";
questions[2][1] = "Clarinet";
questions[2][2] = "Oboe";
questions[2][3] = "Saxophone";
questions[2][4] = "Tubular bells";
answers[2] = "C";
</script>
</head>
<body>

<form name="QuestionForm">
Question
<input type="text" name=txtQNumber size=1>
<script language="JavaScript" type="text/javascript">
   document.write(getQuestion());
</script>
<input type="button" value="Check Question" name="buttonCheckQ"
   οnclick="return buttonCheckQ_onclick()">
</form>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值