質問編集履歴

4

訂正

2018/06/17 11:57

投稿

kei0005
kei0005

スコア19

test CHANGED
@@ -1 +1 @@
1
- JavaScript:onclickで関数呼び出しをしても上手く実行されない
1
+ JavaScript:setIntervalで関数呼び出しをしても実行されない
test CHANGED
File without changes

3

更新

2018/06/17 11:57

投稿

kei0005
kei0005

スコア19

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
- Mozilla Thimbleというウェブ上でJavaScriptを書けるページで書いているのですが、S
13
+ Mozilla Thimbleというウェブ上でJavaScriptを書けるページで書いているのですが、
14
14
 
15
15
  ```
16
16
 
@@ -42,7 +42,7 @@
42
42
 
43
43
  <script>
44
44
 
45
- var time=20;
45
+ var time=5;
46
46
 
47
47
 
48
48
 
@@ -78,13 +78,13 @@
78
78
 
79
79
 
80
80
 
81
- function Life(){ //この関数のif(time<=0)が実行されない
81
+ function Life(){ //この関数のif(time<=0)が実行されない
82
82
 
83
83
  //document.getElementById("t").innerHTML = (t:"time");
84
84
 
85
85
  stopper=0;
86
86
 
87
- time--;
87
+ time--;
88
88
 
89
89
 
90
90
 
@@ -100,9 +100,9 @@
100
100
 
101
101
 
102
102
 
103
- if(time<=0){ //実行されない
103
+ if(time<=0){ //ここがうまく実行されない
104
104
 
105
- window.alert("aaa")//テスト
105
+ window.alert("aaa")
106
106
 
107
107
  document.write('最大数クリック回数:');
108
108
 
@@ -116,33 +116,37 @@
116
116
 
117
117
  }
118
118
 
119
- setInterval(Life,1000);
119
+ setInterval(Life,1000); //おそらくこれも機能していない
120
120
 
121
121
 
122
122
 
123
123
 
124
124
 
125
- function point(x){ //この関数も実行されない
125
+ function point(x){ 
126
126
 
127
- if(x>=document.g_switch.gs_1.value && x>=document.g_switch.gs_2.value && x>=document.g_switch.gs_3.value && x>=document.g_switch.gs_4.value && x>=document.g_switch.gs_5.value && stopper==0)
127
+
128
128
 
129
- {
129
+ if(x>=document.g_switch.gs_1.value && x>=document.g_switch.gs_2.value && x>=document.g_switch.gs_3.value && x>=document.g_switch.gs_4.value && x>=document.g_switch.gs_5.value && stopper==0){
130
130
 
131
- click++;
131
+ click++;
132
132
 
133
- score+=x;
133
+ score+=x;
134
134
 
135
- stopper++;
135
+ stopper++;
136
136
 
137
- }else{
137
+ }else{
138
138
 
139
- score-=x;
139
+ score-=x;
140
140
 
141
- stopper++;
141
+ stopper++;
142
142
 
143
- }
143
+ }
144
144
 
145
+
146
+
145
- }
147
+ }
148
+
149
+
146
150
 
147
151
 
148
152
 

2

更新

2018/06/17 11:47

投稿

kei0005
kei0005

スコア19

test CHANGED
@@ -1 +1 @@
1
- JavaScript:onclickで関数呼び出しをしても実行されない
1
+ JavaScript:onclickで関数呼び出しをしても上手く実行されない
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### 前提・実現したいこと
4
4
 
5
- <input type="button" onclick = "Life()" value="Start" style="widht:50px; height: 50px; font-size:20px;">で実装されているボタンをクリックすると関数Lifeを実行するようにしたいですがそのような関数は未定義ですとエラー出てしまいます
5
+ <input type="button" onclick = "Life()" value="Start" style="widht:50px; height: 50px; font-size:20px;">で実装されているボタンをクリックすると関数Lifeを実行するようにしたいです。5つのボタンには乱数がそれぞれ割り当てられてはいるのですが、変数timeないはsetInterval(Life,1000);がうく動てくれずに困っております
6
6
 
7
7
 
8
8
 
@@ -10,15 +10,15 @@
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
- Mozilla Thimbleというウェブ上でJavaScriptを書けるページで書いているのですが、Startボタンを押すと
13
+ Mozilla Thimbleというウェブ上でJavaScriptを書けるページで書いているのですが、S
14
14
 
15
15
  ```
16
16
 
17
- Uncaught ReferenceError: Life is not defined
17
+ Uncaught TypeError: Cannot read property 'gs_1' of undefined
18
18
 
19
- ReferenceError: Life is not defined
19
+ TypeError: Cannot read property 'gs_1' of undefined
20
20
 
21
- at HTMLInputElement.onclick (https://mozillathimblelivepreview.net/bramble/production/dist/vfs/.anonymous/projects/8d764784-4dea-4c55-a94c-7ddf01b11692/index.html:1964:242)
21
+ at https://mozillathimblelivepreview.net/bramble/production/dist/vfs/.anonymous/projects/900bfa2a-d30d-4e6c-97f0-e5f6980865ee/index.html:1904:25
22
22
 
23
23
  ```
24
24
 
@@ -32,9 +32,9 @@
32
32
 
33
33
  <html>
34
34
 
35
- <head>
35
+ <head>
36
36
 
37
- <h1 id="t"></h1>
37
+ <h1 id="t"></h1>
38
38
 
39
39
  <script type="text/javascript"> </script>
40
40
 
@@ -54,15 +54,15 @@
54
54
 
55
55
 
56
56
 
57
- var r1=(Math.random ( ) * 100)+1;
57
+ var r1=Math.floor(Math.random ( ) * 100)+1;
58
58
 
59
- var r2=(Math.random ( ) * 100)+1;
59
+ var r2=Math.floor(Math.random ( ) * 100)+1;
60
60
 
61
- var r3=(Math.random ( ) * 100)+1;
61
+ var r3=Math.floor(Math.random ( ) * 100)+1;
62
62
 
63
- var r4=(Math.random ( ) * 100)+1;
63
+ var r4=Math.floor(Math.random ( ) * 100)+1;
64
64
 
65
- var r5=(Math.random ( ) * 100)+1;
65
+ var r5=Math.floor(Math.random ( ) * 100)+1;
66
66
 
67
67
 
68
68
 
@@ -78,9 +78,9 @@
78
78
 
79
79
 
80
80
 
81
- function Life(){ //この関数が実行されない
81
+ function Life(){ //この関数内のif(time<=0)が実行されない
82
82
 
83
- document.getElementById("t").innerHTML = (t:"time");
83
+ //document.getElementById("t").innerHTML = (t:"time");
84
84
 
85
85
  stopper=0;
86
86
 
@@ -88,19 +88,21 @@
88
88
 
89
89
 
90
90
 
91
- document.g_switch.gs_1.value = (Math.random ( ) * 100)+1;
91
+ document.g_switch.gs_1.value = Math.floor(Math.random ( ) * 100)+1;
92
92
 
93
- document.g_switch.gs_2.value = (Math.random ( ) * 100)+1;
93
+ document.g_switch.gs_2.value = Math.floor(Math.random ( ) * 100)+1;
94
94
 
95
- document.g_switch.gs_3.value = (Math.random ( ) * 100)+1;
95
+ document.g_switch.gs_3.value = Math.floor(Math.random ( ) * 100)+1;
96
96
 
97
- document.g_switch.gs_4.value = (Math.random ( ) * 100)+1;
97
+ document.g_switch.gs_4.value = Math.floor(Math.random ( ) * 100)+1;
98
98
 
99
- document.g_switch.gs_5.value = (Math.random ( ) * 100)+1;
99
+ document.g_switch.gs_5.value = Math.floor(Math.random ( ) * 100)+1;
100
100
 
101
101
 
102
102
 
103
- if(time<=0){
103
+ if(time<=0){ //実行されない
104
+
105
+ window.alert("aaa")//テスト
104
106
 
105
107
  document.write('最大数クリック回数:');
106
108
 
@@ -110,7 +112,7 @@
110
112
 
111
113
  document.write(score);
112
114
 
113
- }
115
+ }
114
116
 
115
117
  }
116
118
 
@@ -120,7 +122,7 @@
120
122
 
121
123
 
122
124
 
123
- function switch(x){ //この関数も実行されない
125
+ function point(x){ //この関数も実行されない
124
126
 
125
127
  if(x>=document.g_switch.gs_1.value && x>=document.g_switch.gs_2.value && x>=document.g_switch.gs_3.value && x>=document.g_switch.gs_4.value && x>=document.g_switch.gs_5.value && stopper==0)
126
128
 
@@ -142,25 +144,25 @@
142
144
 
143
145
  }
144
146
 
145
-
146
147
 
147
- </script>
148
148
 
149
- <form name = "g_switch">
149
+ </script>
150
150
 
151
-
151
+ <form name = "g_switch">
152
+
153
+
152
154
 
153
155
  <input type="button" onclick = "Life()" value="Start" style="widht:50px; height: 50px; font-size:20px;">
154
156
 
155
- <input type="button" onclick = "switch(document.g_switch.gs_1.value)" name="gs_1" value="SW1" style="widht:50px; height: 50px; font-size:20px;">
157
+ <input type="button" onclick = "point(document.g_switch.gs_1.value)" name="gs_1" value="SW1" style="widht:50px; height: 50px; font-size:20px;">
156
158
 
157
- <input type="button" onclick = "switch(document.g_switch.gs_2.value)" name="gs_2" value="SW2" style="widht:50px; height: 50px; font-size:20px;">
159
+ <input type="button" onclick = "point(document.g_switch.gs_2.value)" name="gs_2" value="SW2" style="widht:50px; height: 50px; font-size:20px;">
158
160
 
159
- <input type="button" onclick = "switch(document.g_switch.gs_3.value)" name="gs_3" value="SW3" style="widht:50px; height: 50px; font-size:20px;">
161
+ <input type="button" onclick = "point(document.g_switch.gs_3.value)" name="gs_3" value="SW3" style="widht:50px; height: 50px; font-size:20px;">
160
162
 
161
- <input type="button" onclick = "switch(document.g_switch.gs_4.value)" name="gs_4" value="SW4" style="widht:50px; height: 50px; font-size:20px;">
163
+ <input type="button" onclick = "point(document.g_switch.gs_4.value)" name="gs_4" value="SW4" style="widht:50px; height: 50px; font-size:20px;">
162
164
 
163
- <input type="button" onclick = "switch(document.g_switch.gs_5.value)" name="gs_5" value="SW5" style="widht:50px; height: 50px; font-size:20px;">
165
+ <input type="button" onclick = "point(document.g_switch.gs_5.value)" name="gs_5" value="SW5" style="widht:50px; height: 50px; font-size:20px;">
164
166
 
165
167
 
166
168
 
@@ -170,7 +172,7 @@
170
172
 
171
173
  </head>
172
174
 
173
- </html>
175
+ </html>
174
176
 
175
177
 
176
178
 

1

追加

2018/06/17 11:39

投稿

kei0005
kei0005

スコア19

test CHANGED
File without changes
test CHANGED
@@ -78,7 +78,7 @@
78
78
 
79
79
 
80
80
 
81
- function Life(){
81
+ function Life(){ //この関数が実行されない
82
82
 
83
83
  document.getElementById("t").innerHTML = (t:"time");
84
84
 
@@ -120,7 +120,7 @@
120
120
 
121
121
 
122
122
 
123
- function switch(x){
123
+ function switch(x){ //この関数も実行されない
124
124
 
125
125
  if(x>=document.g_switch.gs_1.value && x>=document.g_switch.gs_2.value && x>=document.g_switch.gs_3.value && x>=document.g_switch.gs_4.value && x>=document.g_switch.gs_5.value && stopper==0)
126
126