teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

修正

2018/06/06 04:03

投稿

marupi
marupi

スコア6

title CHANGED
File without changes
body CHANGED
@@ -19,7 +19,6 @@
19
19
  <script type="text/javascript">
20
20
 
21
21
  var counter=5;
22
- var i;
23
22
  var setTimer;
24
23
 
25
24
 
@@ -36,28 +35,31 @@
36
35
 
37
36
  document.g_switch.timer.value = counter;
38
37
  counter -= 1;
39
-
38
+
40
39
  if(counter<0){
41
- clearInterval(setTimer);
40
+ endscreen();
42
41
  }
43
-
44
42
  }
45
43
 
44
+
45
+ var clicknum;
46
46
  function point(i){
47
- var max=0;
48
47
  var point=0;
49
- var clicknum=0;
50
-
51
- max = Math.max(document.g_switch.gs_1.value,document.g_switch.gs_2.value,document.g_switch.gs_3.value,document.g_switch.gs_4.value,document.g_switch.gs_5.value);
52
48
 
49
+ var max = Math.max(document.g_switch.gs_1.value,document.g_switch.gs_2.value,document.g_switch.gs_3.value,document.g_switch.gs_4.value,document.g_switch.gs_5.value);
50
+
53
51
  if(document.g_switch.gs_i.value==max){
54
52
  point += document.g_switch.gs_i.value;
53
+ clicknum += 1;
55
54
  }else if(document.g_switch.gs_i.value!=max){
56
55
  point -= document.g_switch.gs_i.value;
57
56
  }
57
+ }
58
58
 
59
+ function endscreen(){
59
- clicknum = clicknum+1;
60
+ clearInterval(setTimer);
61
+ document.getElementById("show").innerHTML = clicknum;
60
- }
62
+ }
61
63
 
62
64
  </script>
63
65
  </head>
@@ -72,10 +74,12 @@
72
74
  <input type="button" name="gs_4" value="SW4" onclick="point(4)" style="widht:50px; height: 50px; font-size:20px;">
73
75
  <input type="button" name="gs_5" value="SW5" onclick="point(5)" style="widht:50px; height: 50px; font-size:20px;">
74
76
 
77
+ <p id="show"></p>
75
78
  </form>
76
79
  </body>
77
80
  </html>
78
81
 
79
82
 
83
+
80
84
  コード
81
85
  ```

1

インデントを揃えました

2018/06/06 04:03

投稿

marupi
marupi

スコア6

title CHANGED
File without changes
body CHANGED
@@ -28,52 +28,52 @@
28
28
  }
29
29
 
30
30
  function changenum(){
31
- document.g_switch.gs_1.value = Math.floor (Math.random ( ) * 100)+1;
31
+ document.g_switch.gs_1.value = Math.floor (Math.random ( ) * 100)+1;
32
- document.g_switch.gs_2.value = Math.floor (Math.random ( ) * 100)+1;
32
+ document.g_switch.gs_2.value = Math.floor (Math.random ( ) * 100)+1;
33
- document.g_switch.gs_3.value = Math.floor (Math.random ( ) * 100)+1;
33
+ document.g_switch.gs_3.value = Math.floor (Math.random ( ) * 100)+1;
34
- document.g_switch.gs_4.value = Math.floor (Math.random ( ) * 100)+1;
34
+ document.g_switch.gs_4.value = Math.floor (Math.random ( ) * 100)+1;
35
- document.g_switch.gs_5.value = Math.floor (Math.random ( ) * 100)+1;
35
+ document.g_switch.gs_5.value = Math.floor (Math.random ( ) * 100)+1;
36
36
 
37
- document.g_switch.timer.value = counter;
37
+ document.g_switch.timer.value = counter;
38
- counter -= 1;
38
+ counter -= 1;
39
+
40
+ if(counter<0){
41
+ clearInterval(setTimer);
42
+ }
39
43
 
40
- if(counter<0){
41
- clearInterval(setTimer);
42
44
  }
43
45
 
46
+ function point(i){
44
- }
47
+ var max=0;
48
+ var point=0;
49
+ var clicknum=0;
50
+
51
+ max = Math.max(document.g_switch.gs_1.value,document.g_switch.gs_2.value,document.g_switch.gs_3.value,document.g_switch.gs_4.value,document.g_switch.gs_5.value);
45
52
 
46
- function point(i){
53
+ if(document.g_switch.gs_i.value==max){
47
- var max=0;
48
- var point=0;
49
- var clicknum=0;
54
+ point += document.g_switch.gs_i.value;
55
+ }else if(document.g_switch.gs_i.value!=max){
56
+ point -= document.g_switch.gs_i.value;
57
+ }
50
58
 
51
- max = Math.max(document.g_switch.gs_1.value,document.g_switch.gs_2.value,document.g_switch.gs_3.value,document.g_switch.gs_4.value,document.g_switch.gs_5.value);
59
+ clicknum = clicknum+1;
60
+ }
52
61
 
53
- if(document.g_switch.gs_i.value==max){
62
+ </script>
63
+ </head>
64
+ <body>
54
- point += document.g_switch.gs_i.value;
65
+ <form name="g_switch">
55
- }else if(document.g_switch.gs_i.value!=max){
56
- point -= document.g_switch.gs_i.value;
57
- }
58
66
 
67
+ <input type="button" name="timer" value="start" onclick="startTimer()" style="widht:50px; height: 50px; font-size:20px;">
59
- clicknum = clicknum+1;
68
+ <p>
60
- }
69
+ <input type="button" name="gs_1" value="SW1" onclick="point(1)" style="widht:50px; height: 50px; font-size:20px;">
70
+ <input type="button" name="gs_2" value="SW2" onclick="point(2)" style="widht:50px; height: 50px; font-size:20px;">
71
+ <input type="button" name="gs_3" value="SW3" onclick="point(3)" style="widht:50px; height: 50px; font-size:20px;">
72
+ <input type="button" name="gs_4" value="SW4" onclick="point(4)" style="widht:50px; height: 50px; font-size:20px;">
73
+ <input type="button" name="gs_5" value="SW5" onclick="point(5)" style="widht:50px; height: 50px; font-size:20px;">
61
74
 
62
- </script>
63
- </head>
64
- <body>
65
- <form name="g_switch">
66
-
67
- <input type="button" name="timer" value="start" onclick="startTimer()" style="widht:50px; height: 50px; font-size:20px;">
68
- <p>
69
- <input type="button" name="gs_1" value="SW1" onclick="point(1)" style="widht:50px; height: 50px; font-size:20px;">
70
- <input type="button" name="gs_2" value="SW2" onclick="point(2)" style="widht:50px; height: 50px; font-size:20px;">
71
- <input type="button" name="gs_3" value="SW3" onclick="point(3)" style="widht:50px; height: 50px; font-size:20px;">
72
- <input type="button" name="gs_4" value="SW4" onclick="point(4)" style="widht:50px; height: 50px; font-size:20px;">
73
- <input type="button" name="gs_5" value="SW5" onclick="point(5)" style="widht:50px; height: 50px; font-size:20px;">
74
-
75
- </form>
75
+ </form>
76
- </body>
76
+ </body>
77
77
  </html>
78
78
 
79
79