27 Kasım 2012 Salı

how to write a quizzing script

1-
Script: You must add this just before the closing tag </head>
<script language="JavaScript">
function calculate ()
{
var flag = false
var trueAnswer="";
for (var i=0;i<arguments.length;++i)
{
for (var j=0;j<5;++j)
{
if(document.all['answer'+String(i+1)][j].value==arguments[i] && document.all['answer'+String(i+1)][j].checked==true )
{
j=5
trueAnswer= trueAnswer + String(i+1) + "."

flag = true;
}
}
}
if (!flag)
alert("Wrong answer");
else
if (trueAnswer.length>2)
alert( trueAnswer +" Questions are true.")
else
alert( trueAnswer +" Questions are true")
}
</script>

2- you can use this form code where you want to create a quiz in <body>...</body> tag


Form Codes:
<form name="form1"><table><tr><td><font color=black> <br />
<b>1.</b></font><b> Beijing, ---- the year 1983, had hardly any cars, but it had more than three million bicycles, and people carried their children ---- the backs of their bicycles.</b> </td></tr>
<tr> <td><br />
<b> A</b><input type="radio" name="answer1" value="a">in / on<br />
<b> B</b><input type="radio" name="answer1" value="b">at / at<br />
<b> C</b><input type="radio" name="answer1" value="c">by / to <br />
<b> D</b><input type="radio" name="answer1" value="d">through / in<br />
<b> E</b><input type="radio" name="answer1" value="e">of / over<br />
</td> </tr>
<tr><td><font color=black> <br />
<b>2.</b></font><b> Penguins are short-sighted ---- land, but see clearly ---- water.</b> </td></tr>
<tr> <td><br />
<b> A</b><input type="radio" name="answer2" value="a">over / on<br />
<b> B</b><input type="radio" name="answer2" value="b">in / off<br />
<b> C</b><input type="radio" name="answer2" value="c">on / under<br />
<b> D</b><input type="radio" name="answer2" value="d">onto / into<br />
<b> E</b><input type="radio" name="answer2" value="e">from / through<br />
</td> </tr>
<tr><td><font color=black> <br />
<b>3.</b></font><b> Mountaineering can kill brain cells, ---- among climbers who do not suffer from altitude sickness.</b> </td></tr>
<tr> <td><br />
<b> A</b><input type="radio" name="answer3" value="a">further<br />
<b> B</b><input type="radio" name="answer3" value="b">just as<br />
<b> C</b><input type="radio" name="answer3" value="c">almost<br />
<b> D</b><input type="radio" name="answer3" value="d">even <br />
<b> E</b><input type="radio" name="answer3" value="e">moreover<br />
</td> </tr>
<tr><td><font color=black> <br />
<b>4.</b></font><b> ---- I see her, she asks me to lend her some money.</b> </td></tr>
<tr> <td><br />
<b> A</b><input type="radio" name="answer4" value="a">Whenever<br />
<b> B</b><input type="radio" name="answer4" value="b">Although<br />
<b> C</b><input type="radio" name="answer4" value="c">In case<br />
<b> D</b><input type="radio" name="answer4" value="d">Even if<br />
<b> E</b><input type="radio" name="answer4" value="e">Unless<br />
</td> </tr>
<tr><td><font color=black> <br />
<b>5.</b></font><b> 7. People in England ---- books about Turkey since the 15th century, but unfortunately an increase in quantity ---- by an increase in quality.</b> </td></tr>
<tr> <td><br />
<b> A</b><input type="radio" name="answer5" value="a">had been writing / does not match<br />
<b> B</b><input type="radio" name="answer5" value="b">are writing / will not be matched<br />
<b> C</b><input type="radio" name="answer5" value="c">had written / are not matching<br />
<b> D</b><input type="radio" name="answer5" value="d">have been writing / has not been matched<br />
<b> E</b><input type="radio" name="answer5" value="e">wrote / had not been matched<br />
</td> </tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
<tr><td><input type="button" value="Show the result" onclick="calculate('a','c','d','a','d')"><br />
</table></form></span>

more?
___in the form "a" is first true answer "d" is last true answer, in other words "a" is true answer of first question, "d" is true anwer of 5. question. they are highlighted with blue color

___to add more question look in <script language="JavaScript">...</script>, do you see the number "5" there just make them 6 / 7 ...or any, they are highlighted with red color

see on action this script here
if you can't see demo please warn me via comment

0 yorum:

Yorum Gönder