質問編集履歴

1

コードの追加

2020/03/04 12:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,109 @@
4
4
 
5
5
 
6
6
 
7
+ サイトの正しいコードも貼り付けています。
8
+
9
+ 違いが見つけられません。
10
+
11
+
12
+
7
- 教えて頂けますと助かります
13
+ 宜しくお願い致します。
14
+
15
+ サイトの正しいコード
16
+
17
+ ```JavaScript
18
+
19
+ 'use strict';
20
+
21
+
22
+
23
+ {
24
+
25
+ const words = [
26
+
27
+ 'apple',
28
+
29
+ 'sky',
30
+
31
+ 'blue',
32
+
33
+ 'middle',
34
+
35
+ 'set',
36
+
37
+ ];
38
+
39
+ let word = words[Math.floor(Math.random() * words.length)];
40
+
41
+ let loc = 0;
42
+
43
+ let score = 0;
44
+
45
+ let miss = 0;
46
+
47
+
48
+
49
+ const target = document.getElementById('target');
50
+
51
+ const scoreLabel = document.getElementById('score');
52
+
53
+ const missLabel = document.getElementById('miss');
54
+
55
+
56
+
57
+ target.textContent = word;
58
+
59
+
60
+
61
+ function updateTarget() {
62
+
63
+ let placeholder = '';
64
+
65
+ for (let i = 0; i < loc; i++) {
66
+
67
+ placeholder += '_';
68
+
69
+ }
70
+
71
+ target.textContent = placeholder + word.substring(loc);
72
+
73
+ }
74
+
75
+
76
+
77
+ window.addEventListener('keydown', e => {
78
+
79
+ if (e.key === word[loc]) {
80
+
81
+ loc++;
82
+
83
+ if (loc === word.length) {
84
+
85
+ word = words[Math.floor(Math.random() * words.length)];
86
+
87
+ loc = 0;
88
+
89
+ }
90
+
91
+ updateTarget();
92
+
93
+ score++;
94
+
95
+ scoreLabel.textContent = score;
96
+
97
+ } else {
98
+
99
+ miss++;
100
+
101
+ missLabel.textContent = miss;
102
+
103
+ }
104
+
105
+ });
106
+
107
+ }
108
+
109
+ ```
8
110
 
9
111
 
10
112
 
@@ -16,6 +118,50 @@
16
118
 
17
119
  <head>
18
120
 
121
+ <meta charset="utf-8">
122
+
123
+ <title>Typing Game</title>
124
+
125
+ <link rel="stylesheet" href="css/styles.css">
126
+
127
+ </head>
128
+
129
+ <body>
130
+
131
+ <p id="target">word</p>
132
+
133
+ <p class="info">
134
+
135
+ Letter count: <span id="score">0</span>,
136
+
137
+ Miss count: <span id="miss">0</span>
138
+
139
+ </p>
140
+
141
+
142
+
143
+ <script src="js/main.js"></script>
144
+
145
+ </body>
146
+
147
+ </html>
148
+
149
+ ```
150
+
151
+
152
+
153
+
154
+
155
+ 自分のコード
156
+
157
+ ```html
158
+
159
+ <!DOCTYPE html>
160
+
161
+ <html lang="ja">
162
+
163
+ <head>
164
+
19
165
  <meta charset="UTF-8">
20
166
 
21
167
  <meta name="viewport" content="width=device-width, initial-scale=1.0">