Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaoru-fukusato/ba214e12f13c8c793aa80e9dd24ad097 to your computer and use it in GitHub Desktop.
Save kaoru-fukusato/ba214e12f13c8c793aa80e9dd24ad097 to your computer and use it in GitHub Desktop.
コピペで学べるプログラミング基本2-9
<script type="text/javascript"><!--
myQA = new Array( // 問題テーブル
"飛行機" , "plane",
"船" , "ship",
"汽車" , "train",
"車" , "car",
"自転車" , "bicycle",
"川" , "river",
"山" , "mountain",
"道路" , "road",
"家" , "house",
"スクリプト", "script"
);
myNowCnt = 0; // 問題を出すテーブルカウンタ
myLastCnt = myQA.length / 2; // 問題の数
myQAno = new Array(myLastCnt); // 問題の順番テーブル
function myQuesInit(){ // 問題テーブルのシャッフル
for (i=0; i<myLastCnt; i++) myQAno[i] = i; // 0~myLastCnt-1を順次セット
for (i=0; i<500; i++){ // 500回 myQAno の内容をシャッフルする
my1 = Math.floor( Math.random() * myLastCnt ); // 0~myLastCnt-1 を決める
my2 = Math.floor( Math.random() * myLastCnt ); // 0~myLastCnt-1 を決める
myBackup = myQAno[my1]; // myQAnoのmy1番目とmy2番目の内容を入れ替える
myQAno[my1] = myQAno[my2];
myQAno[my2] = myBackup;
}
}
function myQues(){
if ( myNowCnt==0 ) myQuesInit(); // 問題をシャッフル
myA = prompt("
問題 : "+myQA[myQAno[myNowCnt]*2],"");
if ( myA != null ){ // キャンセルボタンでない?
if ( myA == myQA[myQAno[myNowCnt]*2+1] ){ // スペル正解?
if (myNowCnt==myLastCnt-1){ // 問題終わった?
myNowCnt=0;
alert("問題終了! お疲れ様でした!");
}else{ // 次の問題へ
myNowCnt++;
myQues();
}
}else{ // スペル間違った?
alert("はずれ! 答えは "+myQA[myQAno[myNowCnt]*2+1]+" です!");
myQues();
}
}else{ // キャンセルボタン押した
myNowCnt=0;
alert("勉強中断 お疲れ様でした!");
}
}
// --></script>
<form name="myForm">
<input type="button" value="英単語の勉強を始める" onclick="myQues()">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment