クイズ・ラジオでポン

<SCRIPT LANGUAGE="JavaScript">
<!--
function saiten(){
	var point=0;	// 点数

	if(document.quiz.a[0].checked){point+=10;}
	if(document.quiz.b[2].checked){point+=10;}
	if(document.quiz.c[1].checked){point+=10;}
	if(document.quiz.d[1].checked){point+=10;}
	if(document.quiz.e[0].checked){point+=10;}
	if(document.quiz.f[0].checked){point+=10;}
	if(document.quiz.g[1].checked){point+=10;}
	if(document.quiz.h[1].checked){point+=10;}
	if(document.quiz.i[2].checked){point+=10;}
	if(document.quiz.j[0].checked){point+=10;}

	if(point==100){
		alert(""+point+"点です。\nおめでとうございます。満点です。\n秘密のページにご招待。");
		location.href="himitu.htm";	// 正解時ジャンプしたいページ
	}
	else{alert(""+point+"点です。\n残念。またチャレンジしてね。");}
	

	// ↓チェックを初期状態に戻します
	// いらなきゃ削除してもOK
	document.quiz.a[0].checked=true;
	document.quiz.b[0].checked=true;
	document.quiz.c[0].checked=true;
	document.quiz.d[0].checked=true;
	document.quiz.e[0].checked=true;
	document.quiz.f[0].checked=true;
	document.quiz.g[0].checked=true;
	document.quiz.h[0].checked=true;
	document.quiz.i[0].checked=true;
	document.quiz.j[0].checked=true;
	// ↑ここまで
}
//-->
</SCRIPT>

<FORM NAME="quiz">
<P>que1 ピカチュウは電気○○?
<BR><input type=radio name="a" checked>ねずみ
 <input type=radio name="a">ねこ
 <input type=radio name="a">うさぎ
<P>que2 埼玉県内の市でないのは?
<BR><input type=radio name="b" checked>春日部
 <input type=radio name="b">秩父
 <input type=radio name="b">町田
<P>que3 パラボラアンテナの「パラボラ」とはどういう意味?
<BR><input type=radio name="c" checked>双曲線
 <input type=radio name="c">放物線
 <input type=radio name="c">直線
<P>que4 SMAPのメンバーでないのは?
<BR><input type=radio name="d" checked>木村
 <input type=radio name="d">仲居
 <input type=radio name="d">香取
<P>que5 「強か」はなんと読む?
<BR><input type=radio name="e" checked>したたか
 <input type=radio name="e">はるか
 <input type=radio name="e">いか
<P>que6 HTMLタグの色指定。赤い色はどれ?
<BR><input type=radio name="f" checked>#ff0000
 <input type=radio name="f">#00ff00
 <input type=radio name="f">#0000ff
<P>que7 清水寺を建てたのは?
<BR><input type=radio name="g" checked>最澄
 <input type=radio name="g">坂上田村麻呂
 <input type=radio name="g">一級建築士
<P>que8 石灰水に息を吹き込むと白くにごりますが、その後もしつこく息を吹き込みつづけると……
<BR><input type=radio name="h" checked>白い固体になり沈殿する
 <input type=radio name="h">透明に戻る
 <input type=radio name="h">もちろん大爆発
<P>que9 一つの外角が30°である正多角形は次のうちどれか。
<BR><input type=radio name="i" checked>正三角形
 <input type=radio name="i">正八角形
 <input type=radio name="i">正十二角形
<P>que10 日本国内でユーザーが最も多いブラウザは?
<BR><input type=radio name="j" checked>IE
 <input type=radio name="j">NN
 <input type=radio name="j">ドリームパスポート
<P><input type=button value=" 採点 " onClick="saiten()">
</FORM>

● 設置方法
1・ラジオボタンのところの問題を書き換えます(HTML分かる人なら問題ないですね?)

2・6〜15行目の
if(document.quiz.a[ここ].checked){point+=10;}
が正解番号なので、自分の作った問題の正解番号に書き換える。

3・上の文をHTML文の<BODY>〜</BODY>の中のお好きなところに貼り付けて下さい。

● 本日のテーマ
一番メインになるのがここですね。6行目以降のカタマリ。

if(document.(フォームの名前).(ラジオボタンの名前)[(正解番号)].checked){point+=(配点);}

一番上なら、quizってフォームのaグループの[0]番目のラジオボタンが
チェックされてるとき10点入るよという意味。
あとは単純に足してこのスクリプトだと100点だったらhimitu.htmにジャンプ。

点数によりメッセージを分岐させたいなら、↓の行を

else{alert(""+point+"点です。\n残念。またチャレンジしてね。");}

↓こんな感じに書き換えます。

else if(point>0 && point<19){alert(""+point+"点です。\nぜんぜん");}
else if(point>20 && point<39){alert(""+point+"点です。\nまだまだ");}
else if(point>40 && point<59){alert(""+point+"点です。\nまあまあ");}
else if(point>60 && point<79){alert(""+point+"点です。\nなかなか");}
else if(point>80 && point<99){alert(""+point+"点です。\nあと一歩");}

オンライン小説界で自作品のクイズとか置いてる人がたまにいるんですが。
それ、いいなーって思って。あとで使おうと思って作りました。
ちなみにこれ、ちょっといじるだけで一問多答にも対応できるように作ってあるんで、
心理テストみたいなのも作れますね。データ作る方がめんどくさいんでやってないですけど。
自分で改造するか私が気が向いて発表するのをお待ちください。

【実行結果】 【戻る】