質問編集履歴
4
文
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,85 +3,4 @@
|
|
3
3
|
アドバイスいただきたいです。
|
4
4
|
現在改善中なのですが、この実装だとクリックをしても次のお題がでず、記入欄もリセットされません。
|
5
5
|
|
6
|
-
```html
|
7
|
-
<body>
|
8
|
-
<p id="odai" style="width:500px; height:60px; padding-top:45px; border:solid 2px; text-align:center;"></p>
|
9
|
-
<form name="form">
|
10
|
-
<p style="text-indent:50px;">↓ここに入力</p>
|
11
|
-
<input type="text" id="user" value="" style="width:400px; height:30px; border:solid 2px; margin-left:50px; text-align:center;"></input>
|
12
|
-
<br>
|
13
|
-
<br>
|
14
|
-
<input type="button" id="button" value="ok" onclick="testfunc()" style="width:60px; height:30px; margin-left:200px;"></input>
|
15
|
-
</form>
|
16
|
-
<p id="timer"></p>
|
17
|
-
<p id="kekka"></p>
|
18
|
-
</body>
|
19
|
-
`
|
6
|
+
`
|
20
|
-
```JavaScript
|
21
|
-
let box = [ //配列でお題を作成
|
22
|
-
"キャンディ",
|
23
|
-
"チョコ",
|
24
|
-
"グミ",
|
25
|
-
"クッキー",
|
26
|
-
"スナック"
|
27
|
-
];
|
28
|
-
|
29
|
-
//お題ランダム表示
|
30
|
-
function question(){
|
31
|
-
let odai = document.getElementById("odai"); //お題の取得
|
32
|
-
let rnd = Math.floor(Math.random() * (box.length -1)); //boxの配列から1個少ない数を最大値とした乱数を作成 box.lengthはboxの中身分だけという意味
|
33
|
-
tmp = box[rnd]; //変数tmpにboxの添字で[rnd]を入れる→ランダムに文章選択、文字列として利用できる
|
34
|
-
box.splice(rnd,1); //rndから該当する配列をspliceで消去.表示
|
35
|
-
odai.textContent = tmp; //tmpをお題欄に出力
|
36
|
-
document.form.reset();
|
37
|
-
}
|
38
|
-
question();
|
39
|
-
//タイマー
|
40
|
-
let timer = document.getElementById("timer");//タイマーの取得
|
41
|
-
let time = 0; //タイム初期化
|
42
|
-
let countdown = null;//countdown初期化
|
43
|
-
|
44
|
-
time = 11;// クリック時も、値を戻す 1秒誤差ありだから11秒
|
45
|
-
if(countdown){
|
46
|
-
clearInterval(countdown);//処理が二重にならないようボタン押下時に一旦タイマークリア
|
47
|
-
}
|
48
|
-
countdown = setInterval(function() { //setInterval()で1秒ずつ表示
|
49
|
-
timer.textContent ='制限時間:' + --time + '秒'; //textContentで文字列と定数を組み合わせた文章を1秒おきに更新する
|
50
|
-
if(time <= 0){ //0になった時点でclearIntervalで止める
|
51
|
-
time = 11; //カウントが終了したら、変数の値を戻す
|
52
|
-
clearInterval(countdown); //clearIntervalで止める
|
53
|
-
user = "";
|
54
|
-
}
|
55
|
-
},1000);
|
56
|
-
timer.textContent = "";
|
57
|
-
|
58
|
-
|
59
|
-
//正誤判定
|
60
|
-
function testfunc() {
|
61
|
-
let button = document.getElementById("button").value; //okボタンの取得
|
62
|
-
let user = document.getElementById("user").value; //userの記入欄取得
|
63
|
-
let kekka = document.getElementById("kekka"); //結果の取得
|
64
|
-
let odai_que = []; //お題を入れる
|
65
|
-
let user_ans = []; //回答を入れる
|
66
|
-
let count_num = 0; //何問目かカウント
|
67
|
-
let count_ans = 0; //正解数のカウント
|
68
|
-
|
69
|
-
odai_que = [tmp]; //お題の配列に上でランダムに1つずつ出力するtmpを入れるお題を取得
|
70
|
-
user_ans = [user]; //userの配列にuserを入れ打った文字を取得
|
71
|
-
count_num = count_num++; //何問目かカウントする変数に何問目かカウントする変数を一つずつ増やす処理をする
|
72
|
-
console.log(tmp);
|
73
|
-
console.log(user);
|
74
|
-
|
75
|
-
function finish(){
|
76
|
-
for(let i = 0;i < user_ans.length;i++){ //user_ansの配列分繰り返す処理
|
77
|
-
if(odai_que === user_ans){ //odai_queとuser_ansが等しかったら
|
78
|
-
count_ans++;//正解数を一つづつ増やす
|
79
|
-
kekka.textContent = "「完璧!」";
|
80
|
-
console.log([user]);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
finish();
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
```
|
3
文
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,21 +2,6 @@
|
|
2
2
|
下記の実装内容に沿って作るのですが、お題の文字と打った文字の正誤判定、それを5回分格納しておいて最後に出力する方法がifやforを使うと思うのですがわかりません。
|
3
3
|
アドバイスいただきたいです。
|
4
4
|
現在改善中なのですが、この実装だとクリックをしても次のお題がでず、記入欄もリセットされません。
|
5
|
-
|
6
|
-
**実装内容**
|
7
|
-
ユーザーがお題のテキストを見て、それと同じ値をテキストボックスに打ち込み、OKボタンを押す。
|
8
|
-
|
9
|
-
OKボタンが押されたらテキストボックスをクリアにし、次のお題を表示する。
|
10
|
-
|
11
|
-
上記を5回繰り返す。
|
12
|
-
|
13
|
-
5回目のokボタンが押された時、お題とユーザーが入力した値が間違っていた文字数の、1〜5回目までの合計数によって、下に表示するテキストを出し分ける。
|
14
|
-
0文字:完璧!
|
15
|
-
1から3文字:おしい!
|
16
|
-
4から8文字:まだまだです。
|
17
|
-
9文字以上:頑張りましょう。
|
18
|
-
|
19
|
-
尚、10秒以内にOKボタンが押されない場合はお題の文字数分の間違いとする。
|
20
5
|
|
21
6
|
```html
|
22
7
|
<body>
|
2
文
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
現在タイピングゲームを実装しています。
|
2
2
|
下記の実装内容に沿って作るのですが、お題の文字と打った文字の正誤判定、それを5回分格納しておいて最後に出力する方法がifやforを使うと思うのですがわかりません。
|
3
3
|
アドバイスいただきたいです。
|
4
|
+
現在改善中なのですが、この実装だとクリックをしても次のお題がでず、記入欄もリセットされません。
|
4
5
|
|
5
6
|
**実装内容**
|
6
7
|
ユーザーがお題のテキストを見て、それと同じ値をテキストボックスに打ち込み、OKボタンを押す。
|
@@ -32,26 +33,29 @@
|
|
32
33
|
</body>
|
33
34
|
```
|
34
35
|
```JavaScript
|
35
|
-
let box = [
|
36
|
+
let box = [ //配列でお題を作成
|
36
37
|
"キャンディ",
|
37
38
|
"チョコ",
|
38
39
|
"グミ",
|
39
40
|
"クッキー",
|
40
41
|
"スナック"
|
41
42
|
];
|
43
|
+
|
44
|
+
//お題ランダム表示
|
45
|
+
function question(){
|
42
46
|
let odai = document.getElementById("odai"); //お題の取得
|
47
|
+
let rnd = Math.floor(Math.random() * (box.length -1)); //boxの配列から1個少ない数を最大値とした乱数を作成 box.lengthはboxの中身分だけという意味
|
48
|
+
tmp = box[rnd]; //変数tmpにboxの添字で[rnd]を入れる→ランダムに文章選択、文字列として利用できる
|
49
|
+
box.splice(rnd,1); //rndから該当する配列をspliceで消去.表示
|
43
|
-
|
50
|
+
odai.textContent = tmp; //tmpをお題欄に出力
|
44
|
-
let button = document.getElementById("button").value; //okボタンの取得
|
45
|
-
|
51
|
+
document.form.reset();
|
52
|
+
}
|
53
|
+
question();
|
54
|
+
//タイマー
|
46
55
|
let timer = document.getElementById("timer");//タイマーの取得
|
47
56
|
let time = 0; //タイム初期化
|
48
57
|
let countdown = null;//countdown初期化
|
49
|
-
let odai_num = odai.length; //odaiの文字数
|
50
|
-
let user_num = 0; //userの文字数
|
51
58
|
|
52
|
-
|
53
|
-
function testfunc() {
|
54
|
-
console.log(user.value);
|
55
59
|
time = 11;// クリック時も、値を戻す 1秒誤差ありだから11秒
|
56
60
|
if(countdown){
|
57
61
|
clearInterval(countdown);//処理が二重にならないようボタン押下時に一旦タイマークリア
|
@@ -59,23 +63,40 @@
|
|
59
63
|
countdown = setInterval(function() { //setInterval()で1秒ずつ表示
|
60
64
|
timer.textContent ='制限時間:' + --time + '秒'; //textContentで文字列と定数を組み合わせた文章を1秒おきに更新する
|
61
65
|
if(time <= 0){ //0になった時点でclearIntervalで止める
|
62
|
-
time = 11; //カウントが終了したら、変数の値を戻す
|
66
|
+
time = 11; //カウントが終了したら、変数の値を戻す
|
63
67
|
clearInterval(countdown); //clearIntervalで止める
|
68
|
+
user = "";
|
64
69
|
}
|
65
70
|
},1000);
|
66
|
-
let rnd = Math.floor(Math.random() * (box.length -1)); //boxの配列から1個少ない数を最大値とした乱数を作成 box.lengthはboxの中身分だけという意味
|
67
|
-
tmp = box[rnd]; //変数tmpにboxの添字で[rnd]を入れる→ランダムに文章選択、文字列として利用できる
|
68
|
-
box.splice(rnd,1); //rndから該当する配列をspliceで消去.表示
|
69
|
-
|
71
|
+
timer.textContent = "";
|
70
72
|
|
73
|
+
|
71
|
-
|
74
|
+
//正誤判定
|
72
|
-
|
75
|
+
function testfunc() {
|
76
|
+
let button = document.getElementById("button").value; //okボタンの取得
|
77
|
+
let user = document.getElementById("user").value; //userの記入欄取得
|
78
|
+
let kekka = document.getElementById("kekka"); //結果の取得
|
79
|
+
let odai_que = []; //お題を入れる
|
80
|
+
let user_ans = []; //回答を入れる
|
81
|
+
let count_num = 0; //何問目かカウント
|
82
|
+
let count_ans = 0; //正解数のカウント
|
83
|
+
|
84
|
+
odai_que = [tmp]; //お題の配列に上でランダムに1つずつ出力するtmpを入れるお題を取得
|
85
|
+
user_ans = [user]; //userの配列にuserを入れ打った文字を取得
|
86
|
+
count_num = count_num++; //何問目かカウントする変数に何問目かカウントする変数を一つずつ増やす処理をする
|
87
|
+
console.log(tmp);
|
88
|
+
console.log(user);
|
89
|
+
|
90
|
+
function finish(){
|
91
|
+
for(let i = 0;i < user_ans.length;i++){ //user_ansの配列分繰り返す処理
|
92
|
+
if(odai_que === user_ans){ //odai_queとuser_ansが等しかったら
|
93
|
+
count_ans++;//正解数を一つづつ増やす
|
73
|
-
kekka.
|
94
|
+
kekka.textContent = "「完璧!」";
|
74
|
-
console.log(
|
95
|
+
console.log([user]);
|
75
|
-
} else {
|
76
|
-
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
finish();
|
77
99
|
}
|
78
100
|
}
|
79
|
-
testfunc();
|
80
101
|
|
81
102
|
```
|
1
文
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,8 +11,8 @@
|
|
11
11
|
|
12
12
|
5回目のokボタンが押された時、お題とユーザーが入力した値が間違っていた文字数の、1〜5回目までの合計数によって、下に表示するテキストを出し分ける。
|
13
13
|
0文字:完璧!
|
14
|
-
1
|
14
|
+
1から3文字:おしい!
|
15
|
-
4
|
15
|
+
4から8文字:まだまだです。
|
16
16
|
9文字以上:頑張りましょう。
|
17
17
|
|
18
18
|
尚、10秒以内にOKボタンが押されない場合はお題の文字数分の間違いとする。
|